android - 什么是 Tools:itemCount 等效于 ExpandableListView?
问题描述
RecyclerView
提供了一种在 Android Studio 的名为 Design 的选项卡中预览布局的便捷方式:
tools:itemCount
有什么等价物ExpandableListView
吗?
我认为答案是“否”,因为我发现另一种工具tools:listitem
确实适用于ExpandableListView
. 我相信这可以通过它的文档来解释,“Intended for: <AdapterView>
(and subclasses like <ListView>
)”。
解决方案
是的你是对的。每个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>
注意显示了三个项目。
推荐阅读
- ruby-on-rails - ActiveModel::UnknownAttributeError: 将徽标上传到 Cloudinary 时健身房的未知属性“徽标”
- python - 面向初学者的 Dataframes 中的基本 Pandas 语法和运算符
- python - 如何在字典中附加相同的键
- powershell - 使用 powershell 创建团队
- attributes - 同样,“AttributeError:类型对象'用户'没有属性'查询'”
- python - Windows - 如何在任何 cmd 目录中运行 Python 文件?
- java - 如何使用 Mockito 模拟 CompletableFutures 列表
- python - 调用另一个类下面的一个类
- r - 如何比浅拷贝更快地通过引用进行更新?
- c# - DataAdapter.Fill 给出错误“在 sys.servers 中找不到服务器‘系统’。”