Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android向ListView添加插入边框_Android_Android Listview - Fatal编程技术网

Android向ListView添加插入边框

Android向ListView添加插入边框,android,android-listview,Android,Android Listview,我已经创建了一个listview,想知道如何将边框添加到我的列表项中,如下图所示 divider drawable.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#cdcdcd"/>

我已经创建了一个listview,想知道如何将边框添加到我的列表项中,如下图所示

divider drawable.xml

<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#cdcdcd"/>    
<stroke android:width="1dp" android:color="#ffffff"/>
<padding android:left="0dp" android:top="0dp"
        android:right="0dp" android:bottom="0dp" />
</shape>

List view.xml

     <ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:divider="@drawable/divider"
    android:dividerHeight="1.0sp"/>

使用:


在listView xml属性中,可以在listView中添加分隔符

 <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="@drawable/divider_line"
        android:layout_weight="1" >
    </ListView>
<RelativeLayout
    android:id="@+id/top_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"

     >


                ................      add views of your choice   

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:src="@drawable/divider_line" />
</RelativeLayout>

或者在自定义布局的底部添加一行,确保在为listview定义自定义布局时底部不应有填充或边距

 <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="@drawable/divider_line"
        android:layout_weight="1" >
    </ListView>
<RelativeLayout
    android:id="@+id/top_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"

     >


                ................      add views of your choice   

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:src="@drawable/divider_line" />
</RelativeLayout>

................      添加您选择的视图

请在oncreate()方法中输入此代码


添加分隔符将提供一条实线我需要的是相同的效果,它似乎是一个插入边框我已经编辑了问题,现在它显示了我的分隔符的代码可绘制,并使用它我得到了一个简单的实线边框我编辑答案再次查看。使用自定义布局并在底部添加视图。对于插入边框,请使用设计的9面片图像或创建自定义可绘制图像。对于定制的抽绳,请遵循此操作。的确如此。一旦问题解决了,请不要忘记接受这个答案作为感谢。Thanksi已经投了赞成票,因为它帮助了我,但我不能把它作为一个完整的答案(希望您理解),这是我无法使用xml drawable实现的效果