Android软键盘仅 float 特定布局

标签 android android-layout android-studio android-xml android-softkeyboard

我有一个布局,代码如下

<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/

相关文章:

android - 用于 Android 应用程序开发的 QT Lite

android - 如何在 ActiveAndroid ORM 中使字段自动递增

android - KitKat specific- android.content.res.Resources$NotFoundException : File res/drawable/list_selector_white. 来自可绘制资源 ID 的 xml

android - 如何创建适合工作表大小且 View 始终与底部对齐的 android Bottom Sheet ?

android - 如何让我的 RelativeLayout 出现在我的 LinearLayout 旁边?

android-studio - 在 Android Studio 中导入 SVG 文件时,渐变没有停止信息错误

java - 使用其他类(class)的 NFC Activity

android - 无法为 Android 解析 XML 文件

android - 如何在android中使用adb shell知道服务是否正在运行

android - app :theme is now deprecated. 请改为使用 android:theme