zoukankan      html  css  js  c++  java
  • listview添加长度不固定分割线

    ListView 添加长度样式不固定的分割线

    ListView可通过配置

    android:dividerline

    android:dividerHeight

    来实现分割listview中item的效果,如图: 
    listview中一条item的布局

    如果想跟上图一样实现这种有设计的分割线样式的时候可以使用下面的方法,这个方法也是参照StackOverFlow解决方案上的方法来实现.

    创建分割线的布局文件:

    list_item_divider.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <inset xmlns:android="http://schemas.android.com/apk/res/android"
        android:insetLeft="50dp"
        android:drawable="@color/grayd">
    </inset>

    在listview的divider属性中引用这个布局

     <ListView
                android:id="@+id/gv_map_list"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="@color/background"
                android:cacheColorHint="@android:color/transparent"
                android:padding="@dimen/space_12"
                android:scrollbars="none"
                android:divider="@drawable/list_item_divider"
                android:dividerHeight="@dimen/space_1"
               />

    这样就能实现图中的效果了。

    PS:

    inset属性 
    定义嵌入的可绘制资源。它必须是根元素。 
    属性(ATTRIBUTES): 
    xmlns:android 
    字符串值,必须的。它定义了XML的命名空间,必须是:http://schemas.android.com/apk/res/android 
    android:drawable 
    要绘制的资源,必须的,它指向一个要嵌入的可绘制资源。 
    android:insetTop 
    尺寸值。用尺寸值或Dimension资源定义顶部的嵌入位置。 
    android:insetRight 
    尺寸值。用尺寸值或Dimension资源定义右边的嵌入位置。 
    android:insetBottom 
    尺寸值。用尺寸值或Dimension资源定义底部的嵌入位置。 
    android:insetLeft 
    尺寸值。用尺寸值或Dimension资源定义左边的嵌入位置。

    <?xml version="1.0" encoding="utf-8"?>
    <inset xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/background"
        android:insetTop="10dp"
        android:insetLeft="10dp"/>

    参考:

    http://stackoverflow.com/questions/14054364/how-to-assign-padding-to-listview-item-divider-line 
    http://blog.csdn.net/think_soft/article/details/7492067

     
     
  • 相关阅读:
    5.搜索-dfs、回溯、bfs
    4.排序算法
    3.二分查找
    2.双指针
    1.贪心算法
    【目录】leetcode刷题
    深度学习的优化与正则化
    什么是深度学习
    循环神经网络
    Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
  • 原文地址:https://www.cnblogs.com/visuals/p/5168928.html
Copyright © 2011-2022 走看看