gpt4 book ai didi

android - 在 CheckBox 之后显示时,RecyclerView 行 TextView 行截断

转载 作者:搜寻专家 更新时间:2023-11-01 08:37:15 26 4
gpt4 key购买 nike

我有一个 RecyclerView,其中的行显示一个复选框,然后显示一个 TextView。当包含 CheckBox 时,TextView 向下移动约 10dp,底线也被截断约 10dp。我希望 TextView 显示在顶部的正确位置,而不是截断最后一行中的文本。请看下面的截图:

Screen shot

行.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="6dp"
android:background="#0FFF0F"
>

<CheckBox
android:id="@+id/chkCompleteTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="top|left"
android:background="#FF00FF"
android:text=""
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_gravity="top|left"
android:text="Here is an example of multi-line text. Notice the top has padding of about 10dp and the botton is cut off by about the same amount. This only occurs when the CheckBox to the left is present."
android:background="#00FFFF"
/>

</LinearLayout>
</layout>

最佳答案

您可以使用 RelativeLayout 轻松实现您想要的效果-

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="12dp"
android:background="#0FFF0F"
>

<CheckBox
android:id="@+id/chkCompleteTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#FF00FF"
android:text=""
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toRightOf="@+id/chkCompleteTask"
android:text="Here is an example of multi-line text. Notice the top has padding of about 10dp and the botton is cut off by about the same amount. This only occurs when the CheckBox to the left is present."
android:background="#00FFFF"
/>

</RelativeLayout>

结果如下图

enter image description here

关于android - 在 CheckBox 之后显示时,RecyclerView 行 TextView 行截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35761654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com