介绍
这期内容当中小编将会给大家带来有关Android应用中出现软键盘不兼容如何解决,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
<强>重写布局布局:强>
public class ResizeLayout extends LinearLayout {, ,private static  int count =, 0;, ,, ,public ResizeLayout (Context 上下文,AttributeSet attrs), {, 超级才能(上下文,attrs);, }大敌; ,, ,@Override ,protected void  onSizeChanged (int w, int h, int oldw,, int oldh), {,, super.onSizeChanged才能(h, w,还以为,oldw, oldh),, ,, Log.e才能(“onSizeChanged “, +, + +,,,=祝辞onResize 叫!,w=? w +,“, h=? h +“, oldw=? oldw +“, oldh=? oldh),, }大敌; ,, ,@Override ,protected void  onLayout (boolean 改变,,int l, int t, int r, int b), {, super.onLayout才能(改变,,,,,,,,b),, Log.e才能(“onLayout “, +, + +,,,=祝辞onLayout 叫!,l=? +, l +,,,, t=? +, t +,“, r=? +, r +,“, b=? b),, }大敌; ,, ,@Override ,protected void  onMeasure (int widthMeasureSpec, int heightMeasureSpec), {, super.onMeasure才能(widthMeasureSpec, heightMeasureSpec),, ,, Log.e才能(“onMeasure “, +, + +,,,=祝辞onMeasure 叫!,widthMeasureSpec=? +, widthMeasureSpec +,,,, heightMeasureSpec=? +, heightMeasureSpec),, 以前,}>我们的布局设置为:
& lt; com.winuxxan.inputMethodTest.ResizeLayout ,xmlns: android=癶ttp://schemas.android.com/apk/res/android", ,android: id=癅 + id/root_layout", ,android: layout_width=癴ill_parent", ,android: layout_height=癴ill_parent", ,android:取向=皏ertical", 在大敌; ,, ,& lt; EditText android:才能layout_width=癴ill_parent", android:才能layout_height=皐rap_content",/在大敌; ,, ,& lt; LinearLayout ,,android: id=癅 + id/bottom_layout", ,,android: layout_width=癴ill_parent", ,,android: layout_height=癴ill_parent", ,,android:取向=皏ertical", ,,android:重力=癰ottom"祝辞s ,, & lt; TextView 大敌; android:才能layout_width=癴ill_parent", android:才能layout_height=皐rap_content", android才能:文本=癅string/hello", android:才能背景=? 77777777“, ,,/比; & lt;/LinearLayout>大敌; & lt;/com.winuxxan.inputMethodTest.ResizeLayout>AndroidManifest。xml的活动设置属性:android: windowSoftInputMode=癮djustResize"
,,,运行程序,点击文本框,查看调试信息:
, E/onMeasure 6(7960):,=祝辞onMeasure 叫!,widthMeasureSpec=1073742144,, heightMeasureSpec =1073742024 ,E/onMeasure 7(7960):,=祝辞onMeasure 叫!,widthMeasureSpec=1073742144,, heightMeasureSpec =1073742025 ,E/onSizeChanged 8(7960):,=祝辞onSizeChanged 叫!,w=320, h=201, oldw=320, oldh=377 ,E/onLayout 9(7960):,=祝辞onLayout 叫!,l=0, t=0时,r=320, b=201,,,从调试结果我们可以看的出,当我们点击文本框后,根布局调用了onMeasure, onSizeChanged和onLayout。
,windowSoftInputMode的值如果设置为adjustPan,那么该活动主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。
,,,上面的例子中,我们将AndroidManifest。xml的属性进行更改:android: windowSoftInputMode=癮djustPan"
,,,重新运行,并点击文本框,查看调试信息:
, E/onMeasure 6(8378):,=祝辞onMeasure 叫!,widthMeasureSpec=1073742144, heightMeasureSpec=1073742200 ,E/onMeasure 7(8378):,=祝辞onMeasure 叫!,widthMeasureSpec=1073742144, heightMeasureSpec=1073742201 ,E/onLayout 8(8378):,=祝辞onLayout 叫!,l=0, t=0时,r=320, b=377,,,null
Android应用中出现软键盘不兼容如何解决