Android实例-解决虚拟键盘遮挡问题(XE8+小米2)

结果:
1.可以自动向上移动,来防遮挡,但同时发现个问题,如果是按硬件返回没有问题,要是点输入法(QQ、百度输入法)上的隐藏就不行了。
2.点击Edit2后出现输入法,点输入法上的隐藏后, 再点Edit2输入法不再显示。
实例代码:
unit Unit1; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ComboEdit,
FMX.Edit, FMX.EditBox, FMX.NumberBox, FMX.DateTimeCtrls, FMX.ScrollBox,
FMX.Memo, FMX.Controls.Presentation, FMX.StdCtrls,
System.Math,//需要引入
FMX.VirtualKeyboard,//需要引入
FMX.Layouts; type
TForm1 = class(TForm)
VertScrollBox1: TVertScrollBox;
Layout1: TLayout;
Memo1: TMemo;
Label1: TLabel;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormFocusChanged(Sender: TObject);
procedure FormVirtualKeyboardHidden(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
procedure FormVirtualKeyboardShown(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
private
//定义移位标记
FKBBounds:TRectF;
FNeedOffset: Boolean;
procedure CalcContentBoundsProc(Sender: TObject; var ContentBounds: TRectF);
procedure RestorePosition;
procedure UpdateKBBounds;
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} //赋值事件
procedure TForm1.FormCreate(Sender: TObject);
begin
VertScrollBox1.OnCalcContentBounds := CalcContentBoundsProc;
end; //每次焦点改变都要更新位置
procedure TForm1.FormFocusChanged(Sender: TObject);
begin
UpdateKBBounds;
end; //输入法隐藏时的处理
procedure TForm1.FormVirtualKeyboardHidden(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
begin
FKBBounds.Create(, , , );
FNeedOffset := False;
RestorePosition;
end; //输入法显示时的处理
procedure TForm1.FormVirtualKeyboardShown(Sender: TObject;
KeyboardVisible: Boolean; const Bounds: TRect);
begin
FKBBounds := TRectF.Create(Bounds);
FKBBounds.TopLeft := ScreenToClient(FKBBounds.TopLeft);
FKBBounds.BottomRight := ScreenToClient(FKBBounds.BottomRight);
UpdateKBBounds;
end; //计算内容边界
procedure TForm1.CalcContentBoundsProc(Sender: TObject;
var ContentBounds: TRectF);
begin
if FNeedOffset and (FKBBounds.Top > ) then
begin
ContentBounds.Bottom := Max(ContentBounds.Bottom, * ClientHeight - FKBBounds.Top);
end;
end; //还原位置
procedure TForm1.RestorePosition;
begin
VertScrollBox1.ViewportPosition := PointF(VertScrollBox1.ViewportPosition.X, );
Layout1.Align := TAlignLayout.Client;
VertScrollBox1.RealignContent;
end; //更新边界
procedure TForm1.UpdateKBBounds;
var
LFocused : TControl;
LFocusRect: TRectF;
begin
FNeedOffset := False;
if Assigned(Focused) then
begin
LFocused := TControl(Focused.GetObject);
LFocusRect := LFocused.AbsoluteRect;
LFocusRect.Offset(VertScrollBox1.ViewportPosition);
if (LFocusRect.IntersectsWith(TRectF.Create(FKBBounds))) and
(LFocusRect.Bottom > FKBBounds.Top) then
begin
FNeedOffset := True;
Layout1.Align := TAlignLayout.Horizontal;
VertScrollBox1.RealignContent;
Application.ProcessMessages;
VertScrollBox1.ViewportPosition := PointF(VertScrollBox1.ViewportPosition.X, LFocusRect.Bottom - FKBBounds.Top);
end;
end;
if not FNeedOffset then
RestorePosition;
end; end.
PS:
1.本实例来自官方demo(D:\DelphiXE8\Users\Public\Documents\Embarcadero\Studio\15.0\Samples\Object Pascal\Mobile Samples\User Interface\ScrollableForm)。
2.控件布局是VertScrollBox1、Layout1,之后的控件都是在Layout1上的。
Android实例-解决虚拟键盘遮挡问题(XE8+小米2)的更多相关文章
- Android实例-解决启动黑屏问题(XE8+小米2)
结果: 1.在启动时马上出现图片界面,但在出现程序界面前会有黑屏,大约有0.2秒左右. 实现: 1.建立2个文件:loading.png和styles.xml: ①其中loading.png是启动时替 ...
- Android实例-获取安卓手机WIFI信息(XE8+小米2)
结果: 1.必须打开Access wifi state权限,不打开权限会出图二的错误. 相关资料: http://blog.csdn.net/lyf_lyf/article/category/1735 ...
- Android实例-MediaPlayer播放音乐和视频(XE8+小米2)
结果: 1.播放视频需要手动放入MediaPlayerControl1控件,设置MediaPlayerControl1.MediaPlayer := MediaPlayer1; 2.播放声音文件正常, ...
- Android实例-录音与回放(播放MP3)(XE8+小米2)
结果: 1.增加ActionList中的Action时,需要跳到Master界面,不能在Android4Phonel界面下. 2.如果不打开权限的话,会提示“该设备不支持停止录音操作”(Record ...
- Android实例-程序界面内截取屏幕(XE8+小米2)
结果: 1.只能截取程序界面内的图片. 2.图片有点不清楚,自己设置清楚度. 实例代码: unit Unit1; interface uses System.SysUtils, System.Type ...
- Android实例-监测网络状态及一些事件(XE8+小米2)
结果: 1.网络连接:是指现在可不可以上网(你非要问我什么是网,我会K你呀的). 2.WIFI网络:是指现在可以上网,用的是不是WIFI网络(如果你打开了WIFI那它会显示正在使用WIFI). 3.移 ...
- Android实例-如何使用系统剪切板(XE8+小米2)
结果: 发现个问题,就是粘贴时会清除之前的信息. unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, S ...
- FIREMONEY手机虚拟键盘遮挡的解决
FIREMONEY手机虚拟键盘遮挡的解决 尝遍了网上人们提供的N种方法之后,发现还是老猫的方法才是彻底解决问题的办法. 老猫“不看后悔XXX”--->RAD10.2.3 Flying Wang ...
- 【转】iOS 上常用的两个功能:点击屏幕和return退出隐藏键盘和解决虚拟键盘挡住UITextField的方法
iOS上面对键盘的处理很不人性化,所以这些功能都需要自己来实现, 首先是点击return和屏幕隐藏键盘 这个首先引用双子座的博客 http://my.oschina.net/plumsoft/blog ...
随机推荐
- POJ 3761 Bubble Sort(乘方取模)
点我看题目 题意 : 冒泡排序的原理众所周知,需要扫描很多遍.而现在是求1到n的各种排列中,需要扫描k遍就变为有序的数列的个数,结果模20100713,当然了,只要数列有序就扫描结束,不需要像真正的冒 ...
- hdu 2509 Be the Winner 博弈论
博弈论水题!!! 代码如下: #include<stdio.h> #include<iostream> using namespace std; int main(){ int ...
- linux distribution是什么?
linux distribution,即Linux发行版,有很多种类,包括Fedora,Ubuntu,Debian,Red Hat,SuSE等,其内核都是差不多的,只是界面设计和功能上各有千秋.
- 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttribute..ctor” 解决方案
静态类中添加如下.此方法本人测试有效. //缺少编译器要求的成员“ystem.Runtime.CompilerServices.ExtensionAttribute..ctor” namespace ...
- 多线程 (三)iOS中的锁
锁的类别:互斥锁,递归锁,条件锁,自旋锁等 锁的实现方式:NSLock,NSRecursiveLock, NSConditionLock,@synchronized,GCD的信号量等 下面说一下常用的 ...
- cctype头文件(字符处理库)的使用
C++ 中cctype头文件的使用 头文件cctype(字符处理库)中定义了有关字符判断与处理的库函数,使用前要包含头文件: #include <cctype> using namespa ...
- UVA548——Tree(中后序建树+DFS)
Tree You are to determine the value of the leaf node in a given binary tree that is the terminal nod ...
- FTPClient 工具类
package com.photoann.core.util; import java.io.BufferedInputStream; import java.io.File; import java ...
- Git教程(3)命令行使用git简单示例
基础 Git系统下的的文件有3种状态: 已修改(modified):已修改表示修改了文件,但还没保存到数据库中. 已暂存(staged) : 已暂存表示对一个已修改文件的当前版本做了标记,使之包含在下 ...
- C#.Net 如何动态加载与卸载程序集(.dll或者.exe)0-------通过应用程序域AppDomain加载和卸载程序集
本博客中以“C#.Net 如何动态加载与卸载程序集(.dll或者.exe)”开头的都是引用莫问奴归处 微软装配车的大门似乎只为货物装载敞开大门,却将卸载工人拒之门外.车门的钥匙只有一把,若要获得还需要 ...