android soft keyboard spoils layout when appears
Here is a layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" />
<FrameLayout
android:background="#0000ff"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" />
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I want blue bar to remain intact when EditText is touched and soft keyboard appears. Ie I want its size and position to be preserved. I tried all four possible values for my activity's parameter android:windowSoftInputMode
in the AndroidManifest. And always my blue bar moves or shrinks on soft keyboard appearing:
android:windowSoftInputMode="adjustUnspecified"
or by default:
android:windowSoftInputMode="adjustPan"
or android:windowSoftInputMode="adjustNothing"
:
android:windowSoftInputMode="adjustResize"
:
Is it ever possible to keep it the same size and position when soft keyb appears?
Since the input is coming into an EditText
of yours, it's always going to move something.
Consider having two layouts, one for when the keyboard is down, one for when the keyboard is up.
Using a ViewSwitcher
may help with that.
you must use <ScrollView>
as main layout. example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
....
</ScrollView>
or use this code in AndroidManiFest.xml:
<activity
android:windowSoftInputMode="adjustNothing">
</activity>
I think it is because of the LinearLayout that you are using. Can you please change your inner layout with relative layout? In your current situation, keyboard just changes the margins between components because of the linear layout. And change your config with adjustNothing.
链接地址: http://www.djcxy.com/p/93422.html上一篇: 打开软键盘时调整布局
下一篇: 出现时,Android软键盘会占用布局