Что такое инструменты: эквивалент itemCount для ExpandableListView? - PullRequest
0 голосов
/ 14 ноября 2018

RecyclerView предлагает удобный способ предварительного просмотра макета на вкладке Android Studio под названием Design:

tools:itemCount

Есть ли эквивалент для ExpandableListView?

Я предполагаю, что ответ "нет", потому что я обнаружил, что другой инструмент, tools:listitem, работает для ExpandableListView. Я полагаю, что это объясняется документацией , "Предназначенной для: <AdapterView> (и подклассов, таких как <ListView>)".

1 Ответ

0 голосов
/ 14 ноября 2018

Да, вы правы. Каждый атрибут 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>

Теперь вы увидите в предварительном просмотре рис. Ниже: enter image description here

обратите внимание, что показаны три элемента.

...