简体   繁体   English

Android:调整软键盘不起作用

[英]Android : Adjust Soft Keyboard not working

I have the following layout file : 我有以下布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:elevation="10dp"
        android:background="@drawable/custom_button_grey"
        >

        <ImageView
            android:id="@+id/listing_image"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:scaleType="centerCrop"
            app:srcCompat="@drawable/background_title" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/listing_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:fontFamily="@font/robotoregular"
                android:text="Title"
                android:textColor="@color/font"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/sdfsd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Listed by :"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:textColor="@color/font"
                />
            <TextView
                android:id="@+id/listing_author"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some random guy"
                android:layout_marginLeft="10dp"
                android:textColor="@color/font"
                />
        </LinearLayout>

    </TableRow>

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:divider="@null"
        android:transcriptMode="alwaysScroll"
        android:stackFromBottom="true"/>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:fitsSystemWindows="true"
        >

        <EditText
            android:id="@+id/input_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@drawable/custom_button"
            android:ems="10"
            android:fontFamily="@font/robotoregular"
            android:hint="Chat here..."
            android:inputType="textPersonName"
            android:padding="15dp"
            android:text=""
            android:textColor="@color/font"
            android:textSize="15dp" />

        <ImageView
            android:id="@+id/send_btn"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:layout_marginHorizontal="5dp"
            app:srcCompat="@drawable/ic_send_black_24dp"
            />
    </TableRow>
</LinearLayout>

and have added the following android:windowSoftInputMode="adjustPan|adjustResize" 并添加了以下android:windowSoftInputMode="adjustPan|adjustResize"

Yet the keyboard still covers my editText. 但是键盘仍然覆盖了我的editText。 As you can see from the layout code the last table row contains an edit text where you can input text to send. 从布局代码中可以看到,最后一个表格行包含一个编辑文本,您可以在其中输入要发送的文本。 I want it above the keyboard so you can see what you are typing. 我希望它在键盘上方,以便您可以看到正在输入的内容。 What is wrong with my layout? 我的布局有什么问题?

Currently it looks like this: 当前看起来像这样:

在此处输入图片说明

EDIT : I wrapped the last table row with a FrameLayout and everything is fine now. 编辑:我用FrameLayout包裹了最后一个表格行,现在一切都很好。

You can modify your code add scrollview for the list. 您可以修改代码,为列表添加scrollview。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="10dp"
                android:padding="10dp">

                <ImageView
                    android:id="@+id/listing_image"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:scaleType="centerCrop" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/listing_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:text="Title"
                        android:textSize="16sp" />

                    <TextView
                        android:id="@+id/sdfsd"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginTop="5dp"
                        android:text="Listed by :" />

                    <TextView
                        android:id="@+id/listing_author"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:text="Some random guy" />
                </LinearLayout>

            </TableRow>

            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:divider="@null"
                android:stackFromBottom="false"
                android:transcriptMode="alwaysScroll" />
        </LinearLayout>
    </ScrollView>
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <EditText
            android:id="@+id/input_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:ems="10"
            android:hint="Chat here..."
            android:inputType="textPersonName"
            android:padding="15dp"
            android:text=""
            android:textSize="15dp" />

        <ImageView
            android:id="@+id/send_btn"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:layout_gravity="center"
            android:layout_marginHorizontal="5dp"
            android:src="@drawable/ic_menu_send" />
    </TableRow>
</LinearLayout>

keyboard will not cover your edit text 键盘不会覆盖您的编辑文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM