Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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_Xml_Listview - Fatal编程技术网

android中listview项的边框

android中listview项的边框,android,xml,listview,Android,Xml,Listview,我想设置Edittext的边框和listview的项目,如图所示: <LinearLayout android:background="#BDD6E0" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" > </LinearLayout&g

我想设置Edittext的边框和listview的项目,如图所示:

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
我的xml代码如下所示:

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>


如何在listview的项目中绘制边框?

listview的背景

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">    
<stroke android:width="1dip" android:color="@color/edt_focused" />
</shape>

将以下形状设置为列表行项目的背景:

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >




    <stroke
        android:width="1dp"
        android:color="#000" />

</shape>

创建一个xml可绘制文件,如
/res/drawable/textlines.xml
,并将其指定为Edittext的后台属性

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
/res/drawable/textlines.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#FF000000" />
            <solid android:color="#FFDDDDDD" />

        </shape>
   </item>

   <item android:top="1dp" android:bottom="1dp"> 
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#FFDDDDDD" />
            <solid android:color="#00000000" />
        </shape>
   </item>

</layer-list>

You use this Drawable for EditText Background or List Item root Layout. 

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
/res/drawable/textlines.xml
您可以将此可绘制文件用于EditText背景或列表项根布局。

列表视图中设置边框
设置属性
android:divider=“@drawable/img\u list”
android:dividerHeight=“1px”
设置分隔器的高度

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
使用以下代码设置
EditText
的边框

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="#ffffff" />
   <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>

所以你的编辑文本看起来像。您可以根据需要更改颜色

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>

将列表子元素的背景设置为

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
 android:background="@drawable/shape"
然后在res>drawable中创建一个新的shape.xml

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
像这样

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
 <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >

        <stroke
            android:width="2dp"
            android:color="#FF000000" />


    </shape>

我认为如果设置listview的transcriptMode属性,它也会显示边框

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>
<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:transcriptMode="normal" >
</ListView>


所以不需要任何形状xml。

我要做的是创建一个九块的简单黑色矩形,并将其设置为背景可能与android:color=“@color/edt_focused”?您想要在边框中显示的颜色“listview的背景”是什么意思?你是说
应该有
android:background=@drawable/myshape
其中
myshape.xml
是你的第一个编码块吗?那么
list\u divider
指的是什么?我对此有异议。我还应用了listSelector,但该选择器没有出现
    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

    </LinearLayout>

    <LinearLayout
        android:background="#BDD6E0"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"  >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Search"
            android:textColor="#000000"
            android:background="#FFFFFF"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/search_pat_edit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:singleLine="true"
            android:textColor="#000000"
            android:layout_weight="4">

        </EditText> 

    </LinearLayout>

    <LinearLayout
        android:background="#c0c0c0"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="6" >

            <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:layout_weight="1" >
            </ListView>

    </LinearLayout>

</LinearLayout>