先进的机器人布局:从图层列表制作一个ListView分 [英] Advanced android layout: making a ListView divider from a layer-list

查看:150
本文介绍了先进的机器人布局:从图层列表制作一个ListView分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考下面的图片来了解我想要做的。它应该是从所提供的图像明显。看起来这应该是pretty的简单。

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>

这篇关于先进的机器人布局:从图层列表制作一个ListView分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆