简体   繁体   English

Android Studio Preview 未显示 ListView 示例

[英]Android Studio Preview is not showing ListView examples

I'm new to app development, so maybe I just made an obvious mistake.我是应用程序开发的新手,所以也许我犯了一个明显的错误。 However my problem is, like I mentioned in the title, my preview is not showing the ListView examples (Picture 1 show what I want the preview to show), but when I add an ArrayList and start it on the emulator every thing is displayed correctly.然而我的问题是,就像我在标题中提到的,我的预览没有显示 ListView 示例(图 1 显示了我想要预览显示的内容),但是当我添加一个 ArrayList 并在模拟器上启动它时,每件事都正确显示.

1 https://i.stack.imgur.com/w4uON.png 1 https://i.stack.imgur.com/w4uON.png

2 https://i.stack.imgur.com/6Hneo.png 2 https://i.stack.imgur.com/6Hneo.png

3 https://imgur.com/sQtBpAo 3 https://imgur.com/sQtBpAo

4 https://imgur.com/a/moT6M4K 4 https://imgur.com/a/moT6M4K

In your layout XML (activity_main.xml), you can add the tools:listitem attribute to the ListView to specify a layout to show in the preview.在您的布局 XML (activity_main.xml) 中,您可以将 tools:listitem 属性添加到 ListView 以指定要在预览中显示的布局。 Like this...像这样...

<ListView
    android:id="@+id/myListView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    tools:listitem="@layout/item_something"
    ... />

Just replace 'item_something' with the name of the layout you want to use for each item.只需将“item_something”替换为您要用于每个项目的布局名称。

PS.附注。 When you're in 'Design' mode rather than editing the XML, look for the attributes with a small spanner icon to the left.当您处于“设计”模式而不是编辑 XML 时,请查找左侧带有小扳手图标的属性。 There are other 'tools' attributes you can use for similar things.还有其他“工具”属性可以用于类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM