我有一个布局,代码如下
<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"
两个布局保持在底部。请帮忙
答案 0 :(得分:2)
你可以说这不起作用
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"
应用于layout1
的{{1}}后,请删除此属性LinearLayout
,但不要求它。
所以现在看起来像这样
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">
和background color
specific height
为了您的理解。
输出
正常屏幕
KeyBoard Open Screen。
请参阅上面的图片我LinearLayout 2
该属性会产生问题,否则每件事情都可以正常工作。
答案 1 :(得分:0)
请使用此,如果您发现任何困难,请告诉我
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--some stuff here-->
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/layout2"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5" />
<ImageButton
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:scaleType="fitStart"
android:src="@drawable/ic_menu_send" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
答案 2 :(得分:0)
删除android:windowSoftInputMode="adjustPan|adjustResize"
然后在软键盘打开时以编程方式隐藏layout2
。当软键盘关闭时,再次使layout2
可见。
这将为用户提供您想要的体验。我不是没有别的办法。但继续搜索。好运
答案 3 :(得分:0)
为两种布局使用不同的主题。
如下: 一个主题是指adjustPan for windowSoftInputMode属性。,另一个主题是指windowSoftInputMode属性的adjustResize。
答案 4 :(得分:0)
最快的方法是在启用软键盘时隐藏布局,并在禁用软键盘时再次显示它们(xml上的layout2
)
也删除此行
android:windowSoftInputMode="adjustPan|adjustResize"
它会起作用,这只是一种简单的方式,我还在寻找你
答案 5 :(得分:0)
将此行放入清单文件中。
android:windowSoftInputMode="stateHidden"