简体   繁体   中英

EditText is getting cut off in ViewHolder of RecyclerView

I have a custom ViewHolder inside of a RecyclerView inside of a LinearLayout in an Activity. I'm trying to get the EditText inside of the ViewHolder to show all of the text inside of it. It keeps getting clipped off from the rest of the view:

在此处输入图片说明

Here's the relevant XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center">
    <CheckBox
        android:id="@+id/add_existing_creature_add_this_creature"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"/>

    <!-- Name of the creature -->
    <TextView
        android:id="@+id/add_existing_creature_list_item_creature_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="8"
        android:textAlignment="center"
        android:textSize="24sp"/>

    <!-- Copies of the creature -->
    <LinearLayout
        android:id="@+id/existing_creature_list_item_copies_group"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:visibility="visible"
        android:padding="4dp" >
        <TextView
            android:labelFor="@+id/add_existing_creature_number_of_copies"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/x"/>
        <EditText
            android:id="@id/add_existing_creature_number_of_copies"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:layout_gravity="bottom"
            android:gravity="bottom"
            android:padding="4dp"/>
    </LinearLayout>
    ....
    <!-- More XML enter code here--->

How do I get the clipping to stop?

You are limited height of your layout ( existing_creature_list_item_copies_group) by other childe of parent LinearLayout (sec linear) test below code and I fixed this problem by padding 2dp text view (add_existing_creature_list_item_creature_name) and fixed child gravity layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:paddingTop="8dp"
    android:paddingBottom="8dp">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <CheckBox
            android:id="@+id/add_existing_creature_add_this_creature"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"/>

        <!-- Name of the creature -->
        <TextView
            android:id="@+id/add_existing_creature_list_item_creature_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:text="5"
            android:padding="2dp"
            android:textAlignment="center"
            android:textSize="24sp"/>

        <!-- Copies of the creature -->
        <LinearLayout
            android:id="@+id/existing_creature_list_item_copies_group"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:visibility="visible"
            android:layout_gravity="center"
            android:gravity="center"
            >
            <TextView
                android:labelFor="@+id/add_existing_creature_number_of_copies"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="x"/>
            <EditText
                android:id="@id/add_existing_creature_number_of_copies"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:layout_gravity="bottom"
                android:gravity="bottom"
                android:text="2"
                android:padding="8dp"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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