Android 软键盘仅浮动特定布局
Android Soft keyboard float only specific 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">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
在上面的代码中,当显示键盘时,我希望 layout2
留在 bottom
和 layout1
到 go up with keyboard
。如果我添加 android:windowSoftInputMode="adjustPan|adjustResize"
两个布局都留在底部。请帮忙
请使用这个,如果您发现任何困难,请告诉我
<?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>
删除 android:windowSoftInputMode="adjustPan|adjustResize"
然后在软键盘打开时以编程方式隐藏 layout2
。当软键盘关闭时,再次使 layout2
可见。
这将为用户提供与您完全相同的体验 want.I不确定是否还有其他方式。但继续寻找。祝你好运
两种布局使用不同的主题。
例如:
一个主题是指 windowSoftInputMode 属性的 adjustPan。
另一个主题是指 windowSoftInputMode 属性的 adjustResize。
最快的方法是在启用软键盘时隐藏布局,并在禁用软键盘时再次显示它们(layout2
on the xml)
也删除此行
android:windowSoftInputMode="adjustPan|adjustResize"
会成功的,这只是一个简单的方法,我还在寻找你
将此行放入您的清单文件中。
android:windowSoftInputMode="stateHidden"
你可以说这是行不通的
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
and specific height
to
LinearLayout 2
for your Understandment.
输出:
普通屏幕
键盘打开屏幕。
改进:
请参阅我制作的上图 Red Mark
属性 造成问题,否则一切正常。
我有布局,代码如下
<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"
两个布局都留在底部。请帮忙
请使用这个,如果您发现任何困难,请告诉我
<?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>
删除 android:windowSoftInputMode="adjustPan|adjustResize"
然后在软键盘打开时以编程方式隐藏 layout2
。当软键盘关闭时,再次使 layout2
可见。
这将为用户提供与您完全相同的体验 want.I不确定是否还有其他方式。但继续寻找。祝你好运
两种布局使用不同的主题。
例如: 一个主题是指 windowSoftInputMode 属性的 adjustPan。
另一个主题是指 windowSoftInputMode 属性的 adjustResize。
最快的方法是在启用软键盘时隐藏布局,并在禁用软键盘时再次显示它们(layout2
on the xml)
也删除此行
android:windowSoftInputMode="adjustPan|adjustResize"
会成功的,这只是一个简单的方法,我还在寻找你
将此行放入您的清单文件中。
android:windowSoftInputMode="stateHidden"
你可以说这是行不通的
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
属性 造成问题,否则一切正常。