Android 软键盘仅浮动特定布局 [英] Android Soft keyboard float only specific layout
问题描述
我有一个布局,代码如下
<!--这里有些东西--><线性布局android:id="@+id/layout1"android:layout_alignParentBottom="true"android:layout_above="@+id/layout2"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"><编辑文本android:layout_width="0dp"android:layout_height="wrap_content"机器人:layout_weight="5"/><图像按钮android:layout_width="50dp"android:layout_height="50dp"android:scaleType="fitStart"机器人:layout_marginLeft="5dp"style="@style/Base.Widget.AppCompat.Button.Borderless"android:src="@drawable/ic_menu_send"/></LinearLayout><线性布局android:id="@+id/layout2"android:layout_alignParentBottom="true"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"><!--这里有些东西--></LinearLayout></RelativeLayout>
在上面的代码中,当键盘显示时,我希望 layout2
留在 bottom
和 layout1
以 上键盘代码>.如果我添加
android:windowSoftInputMode="adjustPan|adjustResize"
两个布局都留在底部.请帮忙
你可以说这是行不通的
android:windowSoftInputMode="adjustPan|adjustResize"
就改这个
android:windowSoftInputMode="stateHidden"
在下面的布局中还有一件事
<!--这里有些东西--><线性布局android:id="@+id/layout1"android:layout_alignParentBottom="true"android:layout_above="@+id/layout2"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"><编辑文本android:layout_width="0dp"android:layout_height="wrap_content"机器人:layout_weight="5"/><图像按钮android:layout_width="50dp"android:layout_height="50dp"android:scaleType="fitStart"机器人:layout_marginLeft="5dp"style="@style/Base.Widget.AppCompat.Button.Borderless"android:src="@drawable/ic_menu_send"/></LinearLayout><线性布局android:id="@+id/layout2"android:layout_alignParentBottom="true"android:layout_width="match_parent"android:layout_height="wrap_content"机器人:方向=水平"android:background="@color/colorPrimary"><!--这里有些东西--></LinearLayout></RelativeLayout>
记住:
当您将此属性 android:layout_above="@+id/layout2"
应用到 LinearLayout
的 layout1
后,然后删除此属性android:layout_alignParentBottom="true"
你不需要它.
现在看起来像这样
<块引用>
注意:我给背景颜色
和特定高度
LinearLayout 2
供您理解.
输出:
普通屏幕
键盘打开屏幕.
改进:
查看上图我制作了 Red Mark
该属性会导致问题,否则一切正常.
I have a layout, code below
<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>
In the above code when keyboard is show i want layout2
to stay in the bottom
and layout1
to go up with keyboard
. if i add android:windowSoftInputMode="adjustPan|adjustResize"
both layout stay in bottom. please help
as you can say this is not work
android:windowSoftInputMode="adjustPan|adjustResize"
just change it this
android:windowSoftInputMode="stateHidden"
and one more thing in your below layout
<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>
Keep in Mind :
When you have applied this property android:layout_above="@+id/layout2"
to layout1
of your LinearLayout
then remove this property android:layout_alignParentBottom="true"
you don't require it.
So Now that look like this
<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.
Output :
Normal Screen
KeyBoard Open Screen.
ImProve :
see the upper Image I make Red Mark
that property create the problem otherwise every thing is work fine.
这篇关于Android 软键盘仅浮动特定布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!