高级Android布局:如何从图层列表中制作ListView分隔符

3
请参考下面的图片来理解我要做的事情。从提供的图片中很明显可以看出。这应该是非常简单的。
问题是,为什么每个列表条目的平铺中间部分的偏移量都不一致? product_list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
        android:layout_height="fill_parent">

    <ListView android:id="@+id/android:list"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:divider="@drawable/product_list_divider"
              android:background="@drawable/main_background_bitmap"/>
    <TextView android:id="@+id/android:empty"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="No results."/>
</LinearLayout>

product_list_divider.xml

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap
            android:src="@drawable/shelf_middle"
            android:tileMode="repeat"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_left"
            android:gravity="left"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_right"
            android:gravity="right"/>
    </item>
</layer-list>

Image to help explain the situation...


这真的很奇怪...看起来好像对于其中一半翻转了中间部分...您使用的是自定义适配器吗? - MrZander
不,它是一个标准的SimpleCursorAdapter。 - Jarrod Smith
1个回答

5

我最终放弃了重复平铺模式,并改为采用以下方式:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap
            android:src="@drawable/bg"
            android:tileMode="repeat" />
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_shine"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_middle_stretch"
            android:gravity="bottom|fill_horizontal"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_side_left"
            android:gravity="left|bottom"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_side_right"
            android:gravity="right|bottom"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_left"
            android:gravity="left|bottom"/>
    </item>
    <item>
        <bitmap
            android:src="@drawable/shelf_right"
            android:gravity="right|bottom"/>
    </item>
</layer-list>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接