gpt4 book ai didi

Android软键盘仅 float 特定布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:14:48 25 4
gpt4 key购买 nike

我有一个布局,代码如下

<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 留在 bottomlayout1 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" 应用到你的 LinearLayoutlayout1 然后删除这个属性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.

输出:

普通屏幕

enter image description here

键盘打开屏幕。

enter image description here

改进:

enter image description here

请参阅上图,我制作了 Red Mark 该属性会产生问题,否则一切正常。

关于Android软键盘仅 float 特定布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38281387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com