自定义列表行中的ListView图形布局 [英] Custom list row in ListView graphical layout
问题描述
有很多很多职位,就如何创建一个自定义行并将其添加到一个ListView问题无限多。我只觉得不过的职位,使用Java code设置自定义行布局文件到列表中。大多数样品做这样的事情:
There are many many posts and an infinite number of questions on how to create a custom row and add it to a ListView. All the posts I find however, use Java code to set the custom row layout file to the list. Most samples do something like this:
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,R.layout.row_layout,R.id.text1,colors);
我在想,如果没有办法做到这一点直接的XML文件?是不是有在ListView控件,您可以设置行的自定义布局文件的属性?
I was wondering if there isn't a way to do this in the XML files directly? Isn't there a property on the ListView where you can set a custom layout file for the rows?
我问的原因是因为我想要做的所有的在Eclipse和我的图形布局工具,我布置工作(大多数)希望能够preVIEW我在里面的布局,而无需启动该应用程序。
The reason I'm asking is because I'm trying to do all (most) of my layout work in the Graphical Layout tool in Eclipse and I would like to be able to preview my layouts in it without launching the app.
当然,这应该是可能的这样或那样的?如果我能在XML到它,我会很高兴,但如果我要编写自定义类,将在图形布局编辑器,会做以及的定制的部分显示出来。
Surely this should be possible in one way or another? If I could to it in the XML I would be very happy but if I have to write a custom class that will show up in the "custom" part of the graphical layout editor that will do as well.
非常感谢您的时间。
推荐答案
有可能在图形编辑器preVIEW列表视图。只需右键单击ListView控件,然后选择preVIEW列表内容。然后选择自定义,然后选择自定义行布局。
It is possible to preview ListViews in the graphical editor. Just right-click the ListView and choose "Preview List Content". Then select "Custom" and choose the custom row layout.
下面是一个例子:
my_custom_list.xml
my_custom_list.xml
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false">
<!-- Preview: listitem=@layout/account_list_item -->
</ListView>
my_custom_row.xml
my_custom_row.xml
<CheckBox
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
/>
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="mail@mail.com" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/secondLine"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="Account name" />
在my_custom_list.xml的图形编辑器中,右键单击列表中。您可以选择自定义选项my_custom_row在preVIEW列表内容。
In the graphical editor of my_custom_list.xml, right click the list. Choose the my_custom_row from the "Custom" option in the "Preview List Content".
这篇关于自定义列表行中的ListView图形布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!