固定软键盘上方的布局

时间:2018-06-22 11:54:27

标签: java android xml android-layout

我知道这个问题已经存在很长时间了,但是对于我来说似乎没有任何作用。

怎么了

enter image description here enter image description here

如屏幕截图所示,具有微调器的布局没有向上推,而是由软键盘覆盖。我希望此布局在弹出时位于键盘上方。

我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context="believe.cht.speak.MainActivity">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:layout_gravity="center_horizontal"
        android:layout_margin="16dp"
        android:src="@drawable/ic_bubble"
        android:tint="@color/blue" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:gravity="top|start"
        android:hint="Start typing..."
        android:padding="8dp" />

    <ImageView
        android:id="@+id/shadow"
        android:layout_width="match_parent"
        android:layout_height="6dp"
        android:src="@drawable/shadow" />

    <RelativeLayout
        android:id="@+id/spinnerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/blue">

        <Spinner

            android:id="@+id/spinner"
            android:layout_width="200dp"
            android:layout_height="48dp"
            android:layout_alignParentEnd="true" />

    </RelativeLayout>

</LinearLayout>

我尝试过的事情

android:windowSoftInputMode="adjustResize"

android:windowSoftInputMode="adjustPan" //in the manifest, also tried combining the two

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //in the activity

<item name="android:windowActionBarOverlay">true</item> //in styles.xml

3 个答案:

答案 0 :(得分:1)

尝试一下

res.send(JSON.stringify(jsonString))

清单文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/logo"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_gravity="center_horizontal"
            android:layout_margin="16dp"
            android:src="@drawable/ic_message" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:gravity="top|start"
            android:hint="Start typing..."
            android:padding="8dp" />

        <ImageView
            android:id="@+id/shadow"
            android:layout_width="match_parent"
            android:layout_height="6dp"
            android:src="@drawable/ic_camera" />

        <RelativeLayout
            android:id="@+id/spinnerLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/colorPrimary">

            <Spinner

                android:id="@+id/spinner"
                android:layout_width="200dp"
                android:layout_height="48dp"
                android:layout_alignParentEnd="true" />

        </RelativeLayout>

    </LinearLayout>
</ScrollView>

输出

enter image description here enter image description here

答案 1 :(得分:0)

尝试使用RelativeLayout而不是LinearLayout并将android:alignParentBottom="true"添加到您的spinnerLayout

答案 2 :(得分:0)

除了上面的Nilesh回答外,即使代码有效,它也不适用于我的Java类。原因是我隐藏了状态栏,

requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

使用提供的代码并保持状态栏不变。不知道为什么。如果有人可以解释这一点,我会有所帮助。