【问题标题】:Why my edittext layout and keyboard overlaps?为什么我的 edittext 布局和键盘重叠?
【发布时间】:2019-04-09 19:28:18
【问题描述】:

当我点击 edittext 我的布局停留在键盘下。它重叠。单击edittext时,我想向上移动键盘。你能帮我解决这个问题吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/rootLayout"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/white">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/footer_height"
        android:layout_alignParentTop="true"
        android:background="@color/colorPrimary"
        android:elevation="1dp"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:id="@+id/chat_back_button"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="80dp"
                android:layout_height="40dp"
                android:layout_centerVertical="true"
                android:background="@drawable/image_back"/>

            <TextView
                android:id="@+id/chat_Header_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/str_chat"
                android:textColor="@android:color/white"
                android:textSize="@dimen/activity_list_header_size"/>
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="54dp">

        <ListView
            android:id="@+id/chat_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:transcriptMode="alwaysScroll"></ListView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/chat_edit_layout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/colorPrimaryDark"
        android:orientation="vertical"
        android:padding="0.5dp"
        android:layout_above="@+id/chat_footer_layout"
        android:layout_centerHorizontal="true">

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

            <EditText
                android:id="@+id/chat_edit"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.8"
                android:background="@android:color/white"
                android:gravity="start|center_vertical"
                android:hint="@string/mesaj_yaz"
                android:padding="2dp"/>

            <ImageView
                android:id="@+id/chat_send"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.2"
                android:onClick="sendMessage"
                android:src="@drawable/chat_icon"
                android:visibility="gone"/>

            <TextView
                android:id="@+id/chat_text"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.3"
                android:background="@color/colorPrimaryDark"
                android:gravity="center"
                android:onClick="sendMessage"
                android:text="@string/gonder"
                android:textColor="@android:color/white"
                android:textSize="@dimen/activity_list_header_size"/>

        </LinearLayout>

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/chat_footer_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/footer_height"
        android:layout_alignParentBottom="true"
        >
        <!--android:elevation="1dp"-->

        <ImageView
            android:id="@+id/chat_footer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"/>
    </RelativeLayout>

我添加了 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 在 onCreate() 方法中。我还在 Manifest.xml 中的活动中添加了android:windowSoftInputMode="adjustResize"。但是还是不行。

【问题讨论】:

  • 有时是设备问题或操作系统问题

标签: android android-layout android-xml


【解决方案1】:

尝试将 scrollView 作为父布局并在清单中使用“adjustPan”

    android:id="@+id/main_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多