*****阅读此篇文章大约需[三分钟],了解知识点[一个]*****
[更正]《Android编程权威指南》9.4定制列表项P167页的小错误:
应将代码 android:layout_height="match_parent"改成android:layout_height="wrap_content"
不然会导致其内仅仅三个子view的内容却占了整个屏幕
//list_item_crime.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/list_item_crime_solved_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="4dp"
android:text="CheckBox" />
<TextView
android:id="@+id/list_item_crime_title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/list_item_crime_solved_check_box"
android:padding="4dp"
android:textStyle="bold"
android:text="CrimeTitle" />
<TextView
android:id="@+id/list_item_crime_date_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/list_item_crime_solved_check_box"
android:layout_below="@id/list_item_crime_title_text_view"
android:padding="4dp"
android:text="CrimeDate" />
</RelativeLayout>
Change to⬇️
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/list_item_crime_solved_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="4dp"
android:text="CheckBox" />
<TextView
android:id="@+id/list_item_crime_title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/list_item_crime_solved_check_box"
android:padding="4dp"
android:text="CrimeTitle"
android:textStyle="bold" />
<TextView
android:id="@+id/list_item_crime_date_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/list_item_crime_title_text_view"
android:layout_toLeftOf="@+id/list_item_crime_solved_check_box"
android:padding="4dp"
android:text="CrimeDate" />
</RelativeLayout>