如何使用自定义行和标题布局预览 Android ListView [英] How to preview Android ListView with custom row and header layout

查看:30
本文介绍了如何使用自定义行和标题布局预览 Android ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经多次为标题和行项目创建了一个带有自定义布局的列表视图,但总是让我烦恼的是 Android Studio 中的 UI 预览不显示预览.显然,因为自定义布局是由 ListView 或 CursorAdapter 以编程方式加载的,但是如果我想知道如何在 xml 中指定页眉和页脚布局以便我可以看到预览呢?有人知道怎么做吗?

I have created a list view with a custom layout for the header and rows items many times but what always annoys me is the UI preview in Android Studio does not show a preview. Obviously because the custom layouts are loaded programmatically by the ListView or CursorAdapter but what if I wanted to some how specify a header and footer layout in xml so that I could see a preview. Any one know how to do that?

推荐答案

您可以使用 tools:listitem.只需在布局的根目录中添加工具命名空间

You can use tools:listitem. Just add the tools namespace in the root of the layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    (...)

然后在您的 ListView 中设置您的列表项布局

and then in your ListView set your list item layout

 <ListView
    android:id="@+id/mylistView"
    tools:listitem="@layout/my_list_item"
    (...)

也可以使用 listheader/listfooter 设置页眉/页脚.

Is also possible to set header/footer with listheader/listfooter.

这篇关于如何使用自定义行和标题布局预览 Android ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆