我有一个布局,代码如下
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="@+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:src="@drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
在上面的代码中,当显示键盘时,我希望 layout2
留在 bottom
和 layout1
go up with keyboard
。如果我添加 android:windowSoftInputMode="adjustPan|adjustResize"
两个布局都留在底部。请帮忙
最佳答案
你可以说这是行不通的
android:windowSoftInputMode="adjustPan|adjustResize"
改成这样
android:windowSoftInputMode="stateHidden"
在你下面的布局中还有一件事
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="@+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:src="@drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/colorPrimary">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
牢记:
当你将这个属性 android:layout_above="@+id/layout2"
应用到你的 LinearLayout
的 layout1
然后删除这个属性android:layout_alignParentBottom="true"
你不需要它。
现在看起来像这样
<LinearLayout
android:id="@+id/layout1"
android:layout_above="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Note : I am giving
background color
andspecific height
toLinearLayout 2
for your Understandment.
输出:
普通屏幕
键盘打开屏幕。
改进:
请参阅上图,我制作了 Red Mark
该属性会产生问题,否则一切正常。
关于Android软键盘仅 float 特定布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38281387/