在CheckBox之后显示时,RecyclerView行TextView行截止

时间:2016-03-03 01:49:55

标签: android

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

Screen shot

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

1 个答案:

答案 0 :(得分:3)

您可以使用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