【问题标题】:What is a tools:itemCount equivalent for ExpandableListView?什么是 Tools:itemCount 等效于 ExpandableListView?
【发布时间】:2019-04-16 20:19:28
【问题描述】:

RecyclerView offers a convenient way to preview the layout 在 Android Studio 的名为“设计”的选项卡中:

tools:itemCount

ExpandableListView 有什么等价物吗?

我认为答案是否定的,因为我发现另一个工具 tools:listitem 确实适用于 ExpandableListView。我相信这可以通过它的documentation 来解释,“用于:<AdapterView>(以及像<ListView> 这样的子类)”。

【问题讨论】:

    标签: android android-studio android-layout expandablelistview


    【解决方案1】:

    是的,你是对的。每个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>
    

    sample_list_item 布局:

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

    现在您将在预览中看到如下图:

    注意这里显示了三个项目。

    【讨论】:

    • ExpandableListView 无明显限制地重复。
    猜你喜欢
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 2017-07-31
    • 2014-02-09
    相关资源
    最近更新 更多