【问题标题】:EditText is getting cut off in ViewHolder of RecyclerViewEditText 在 RecyclerView 的 ViewHolder 中被切断
【发布时间】:2018-11-05 20:41:01
【问题描述】:

我在 Activity 的 LinearLayout 内的 RecyclerView 内有一个自定义 ViewHolder。我试图让 ViewHolder 中的 EditText 显示其中的所有文本。它不断地从视图的其余部分中被剪掉:

这是相关的 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--->

如何让剪辑停止?

【问题讨论】:

    标签: android


    【解决方案1】:

    您的布局高度有限 (existing_creature_list_item_copies_group) 由父 LinearLayout 的其他子项(秒线性) 测试下面的代码,我通过填充 2dp 文本视图(add_existing_creature_list_item_creature_name)和固定子重力布局解决了这个问题:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多