3

我创建了一个自定义 xml 文件,其中包含一些构成 ListView 中的行的元素。我已将 ListView 的预览设置为此 xml 文件。我不知道如何摆脱默认的“项目 1”、“项目 2”、“项目 3”......但是。

有没有人知道可能导致这种情况的原因?

这是代码和屏幕截图:

my_custom_list.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="8dp"
         android:paddingRight="8dp">


     <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/my_custom_list_row -->
     </ListView>
 </LinearLayout>

my_custom_list_row.xml

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="6dip"
    android:orientation="horizontal">

    <CheckBox
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
         />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="6dip"
        android:orientation="vertical" >

        <TextView  
            android:id="@+id/secondLine"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:ellipsize="marquee"
            android:text="Senders Name"
            android:textStyle="bold" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"   
            android:gravity="center_vertical"
            android:text="Subject"

            android:textStyle="italic" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:lines="3"
            android:gravity="center_vertical"
            android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla viverra mattis nulla nec sollicitudin." />

      </LinearLayout>

</LinearLayout>

列表截图

4

1 回答 1

0

不,这似乎不可能,或者这是我一直遇到的 ADT 插件中的一个错误。我只是通过预览行来确保它看起来不错。如果您需要渲染 UI 图像,您可以使用Pencil之类的工具并将Android Stencils导入其中。

于 2012-10-02T15:48:10.283 回答