android - EditText 在 RecyclerView 的 ViewHolder 中被切断
问题描述
我在 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--->
如何让剪辑停止?
解决方案
您的布局(existing_creature_list_item_copies_group)的高度受限于父LinearLayout(sec线性)测试下面的代码,我通过填充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>
推荐阅读
- ios - 如何在 iOS Objective c 中进行 iOS 导航健康设置?
- javascript - 反应音乐播放器
- c# - 为 CLR 聚合实现 IBinarySerialize
- c - gcc 包含标头并在预处理后获取输出
- typescript - Typescript 动态参数和返回类型
- python - 将数据从 JSON 写入 CSV 文件
- control-m - 在 Control-M 中从订单日期减去 2 分钟
- javascript - 用 html5 画布绘制地砖,但它是完美的。我怎样才能使用 webgl 变得逼真
- c# - 在表单面板的中心显示 msgbox
- php - 即使我安装了 php8.0-xml,也找不到类 'DOMDocument'