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 ...
随机推荐
- 微软在 .NET 3.5 新增了一个 HashSet 类,在 .NET 4 新增了一个 SortedSet 类,本文介绍他们的特性,并比较他们的异同。
微软在 .NET 3.5 新增了一个 HashSet 类,在 .NET 4 新增了一个 SortedSet 类,本文介绍他们的特性,并比较他们的异同. .NET Collection 函数库的 Has ...
- PLS-00215:字符串长度限制在范围
在Oracle中有一张people表 创建跟新表的存储过程 修改定义字段长度 总结:在Oracle中执行存储过程时,输出参数的长度要与原表中字段长度一致!
- *MySQL卸载之后无法重装,卡在Apply security settings:Error Nr.1045
- 93. Restore IP Addresses
题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...
- Android invalidate()自动清屏,屏幕刷新
invalidate()是用来刷新View的,必须是在UI线程中进行工作.比如在修改某个view的显示时,调用invalidate()才能看到重新绘制的界面.invalidate()的调用是把之前的旧 ...
- MapReduce编程系列 — 4:排序
1.项目名称: 2.程序代码: package com.sort; import java.io.IOException; import org.apache.hadoop.conf.Configur ...
- Statement和PreparedStatement的特点 MySQL数据库分页 存取大对象 批处理 获取数据库主键值
1 Statement和PreparedStatement的特点 a)对于创建和删除表或数据库,我们可以使用executeUpdate(),该方法返回0,表示未影向表中任何记录 b)对于创建和 ...
- 在C++中调用DLL中的函数
如何在C++中调用DLL中的函数 应用程序使用DLL可以采用两种方式:一种是隐式链接,另一种是显式链接.在使用DLL之前首先要知道DLL中函数的结构信息.Visual C++6.0在VC\bin目录下 ...
- hdu4177:Super Mario
主席树+离散化.给一段区间.多次询问[l,r]中有多少个数小于k.啊主席树用指针版写出来优美多了QAQ... #include<cstdio> #include<cstring> ...
- 【转】跟着开涛学SpringMVC
跟着开涛学SpringMVC 第一章源代码下载 博客分类: 跟开涛学SpringMVC 跟开涛学SpringMVC 源代码请到附件中下载. 其他下载: 跟着开涛学SpringMVC 第一章源代码下载 ...