美文网首页安卓开发安卓资源收集安卓自定义VIEW
[更正]《Android编程权威指南》9.4定制列表项P167页

[更正]《Android编程权威指南》9.4定制列表项P167页

作者: Topus | 来源:发表于2018-10-26 22:44 被阅读1次
*****阅读此篇文章大约需[三分钟],了解知识点[一个]*****

[更正]《Android编程权威指南》9.4定制列表项P167页的小错误:

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

按照书上来的效果⬇️

一屏只显示一个ViewHolder

Change to⬇️

正常

相关文章

网友评论

    本文标题:[更正]《Android编程权威指南》9.4定制列表项P167页

    本文链接:https://www.haomeiwen.com/subject/dnfrtqtx.html