ExpandableListView 中的 "tools:itemCount" 等效于什么?

5
1个回答

0

是的,你说得对。每个tools:属性都属于不同的类。

你可以像下面这样集成这两个属性。

主要布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    tools:context=".MainActivity">

    <ExpandableListView
        android:id="@+id/expandableListView"
        tools:listitem="@layout/sample_list_item" //notice this line
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
        android:divider="@android:color/darker_gray"
        android:dividerHeight="0.5dp" />

</RelativeLayout>

样例列表项布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:itemCount="3"  //notice this line
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>

现在您将在预览中看到如下图所示: {{link1:输入图像描述}}

请注意,显示了三个项目。


ExpandableListView 可以无限重复。 - Michael Osofsky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接