【问题标题】:Why my EditText gets covered by the layout?为什么我的 EditText 被布局覆盖?
【发布时间】:2019-06-01 01:49:06
【问题描述】:

我有一个简单的 EditText,但是当我展开它时,它会被剪掉。可能是我的 Layout 组合造成的,有人知道是什么问题吗?

我的xml文件如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="@dimen/surround_paddings"
    android:layout_margin="@dimen/surround_margins">

    <ImageView
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/back_arrow"
        android:layout_gravity="left"
        android:layout_weight="0.5"
        android:padding="10dp"/>

    <TextView
        android:id="@+id/serverRoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Server 0 - Sala 0"
        android:textSize="@dimen/subtitle"
        android:fontFamily="@font/baloo"
        android:layout_marginLeft="@dimen/surround_margins"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_weight="9"
        android:lineSpacingExtra="@dimen/text_spacing"/>

</LinearLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_marginTop="-5dp"
    android:background="@color/colorAccent"/>

<TextView
    android:id="@+id/subject"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="@dimen/subtitle"
    android:fontFamily="@font/baloo"
    android:text="@string/subject"
    android:layout_gravity="center"
    android:gravity="center"
    android:textColor="@color/colorPrimaryDark"
    android:lineSpacingExtra="@dimen/text_spacing"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/rounded_grey">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1"
        android:background="@drawable/rounded_grey"
        android:baselineAligned="false">

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rvMessages"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="@dimen/surround_margins"
                android:background="@drawable/rounded_primary_double"
                android:padding="10dp"
                android:layout_weight="1"
                android:divider="@color/colorAccent"
                android:dividerHeight="1.3dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:layout_weight="9"
                android:padding="@dimen/surround_paddings"
                android:background="@drawable/rounded_white">

                <LinearLayout
                    android:id="@+id/commentIcon"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/rounded_primary_dark_circle"
                    android:src="@drawable/pencil_icon"
                    android:elevation="@dimen/elevation1"
                    android:orientation="vertical"
                    android:layout_gravity="center"
                    android:layout_margin="@dimen/surround_margins"
                    android:gravity="center">

                    <TextView
                        android:id="@+id/questionsNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0"
                        android:fontFamily="@font/baloo"
                        android:textColor="@color/colorAccent"
                        android:textSize="@dimen/subtitle"
                        android:layout_gravity="center"
                        android:gravity="center"/>
                </LinearLayout>

                <EditText
                    android:layout_weight="7"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/rounded_white"
                    android:hint="@string/wait_your_time"
                    android:fontFamily="@font/baloo"
                    android:layout_marginLeft="@dimen/surround_margins"
                    android:autofillHints="@string/wait_your_time"
                    android:inputType="text" />

                <LinearLayout
                    android:id="@+id/sendIcon"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/rounded_accent_circle"
                    android:src="@drawable/pencil_icon"
                    android:elevation="@dimen/elevation1"
                    android:orientation="vertical"
                    android:layout_gravity="center"
                    android:padding="@dimen/surround_paddings"
                    android:layout_margin="@dimen/surround_margins"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@mipmap/send_icon"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="8"
            android:layout_gravity="center"
            android:gravity="center"
            android:background="@drawable/rounded_grey"
            android:orientation="vertical">

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

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

                    <ImageView
                        android:id="@+id/nextIcon"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/next_icon"
                        android:layout_gravity="center"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/jump_time"
                        android:textSize="@dimen/small_text"
                        android:lineSpacingExtra="@dimen/text_spacing"
                        android:fontFamily="@font/baloo"
                        android:gravity="center"
                        android:layout_marginTop="@dimen/negative"
                        android:layout_gravity="center"
                        android:textColor="@color/black"/>
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="2dp"
                        android:layout_marginTop="-5dp"
                        android:background="@color/colorAccent"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/whose_time"
                        android:textSize="@dimen/small_text"
                        android:lineSpacingExtra="@dimen/text_spacing"
                        android:fontFamily="@font/baloo"
                        android:gravity="center"
                        android:layout_marginTop="@dimen/negative"
                        android:layout_gravity="center"
                        android:textColor="@color/black"/>
                </LinearLayout>

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rvLine"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="@dimen/surround_margins"
                    android:background="@drawable/rounded_grey"
                    android:padding="@dimen/surround_paddings"
                    android:layout_gravity="center"
                    android:layout_weight="2"
                    android:divider="@color/colorAccent"
                    android:dividerHeight="1.3dp"/>

            </LinearLayout>

            <LinearLayout
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="9"
                android:orientation="vertical">

                <View
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:background="@color/colorAccent"/>

                <LinearLayout
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/rounded_accent_circle"
                    android:src="@drawable/pencil_icon"
                    android:elevation="@dimen/elevation1"
                    android:orientation="vertical"
                    android:layout_gravity="center"
                    android:layout_margin="@dimen/surround_margins"
                    android:gravity="center">

                    <TextView
                        android:id="@+id/timer"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0"
                        android:fontFamily="@font/baloo"
                        android:textColor="@color/colorPrimaryDark"
                        android:textSize="@dimen/subtitle"
                        android:layout_gravity="center"
                        android:gravity="center"/>
                </LinearLayout>
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

下面是我尝试输入内容时发生的情况: keyboard not expanded

Here's the problem

如果有这么多的布局可能会导致它,我想知道。我想我应该留出足够的空间来显示整个editText

【问题讨论】:

    标签: java android android-edittext height android-linearlayout


    【解决方案1】:

    为了防止这种情况,您可以将其添加到清单中:

    <activity
     android:windowSoftInputMode="adjustPan">
    </activity>
    

    如果这对您不起作用,您可以直接在 xml 中使用它:

    android:windowSoftInputMode="adjustNothing|adjustResize"
    

    有时这也不能解决问题,您必须动态添加此属性:

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    

    【讨论】:

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