简体   繁体   中英

Advanced android layout: making a ListView divider from a layer-list

Refer to the image below to understand what I'm trying to do. It should be obvious from the image provided. It seems like this should be pretty simple.

The question is, why is the tiled middle section offset by an inconsistent amount for each list entry?

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>

图片有助于解释情况......

I ended up abandoning the repeat tile mode and did it like this instead:

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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