2013-02-07 45 views
0

我創建了一個列表視圖,並想知道如何邊框添加到我的列表中的項目,如下面的圖片的Android添加插圖邊框若要列表視圖

enter image description here

分頻器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> 

列表視圖.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"/> 

回答

0

使用:

 android:divider="@drawable/mydivider" 

在你的ListView XML屬性

+0

此代碼和mydivider將是一個圖像權利?? –

+0

任何類型的繪圖(圖像,顏色,XML可繪製).. –

+0

這就是我無法實現這種效果使用xml繪製 –

1

您可以在列表視圖中添加一個分頻器。

<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> 
+0

添加分頻器將給一個堅實的線我需要的是相同的效果,它似乎是一個插入邊框 –

+0

我編輯了這個問題,現在它顯示了我的分隔線可繪製的代碼,並使用我得到一個簡單的實心邊框 –

+0

我編輯答案再次看到它。使用自定義佈局並在底部添加視圖。對於插頁邊框,可以設計9貼片圖像或創建自定義繪圖。按照這個自定義drawables。 http://developer.android.com/guide/topics/resources/drawable-resource.html – Jan

0

請輸入上onCreate()方法

listView = (ListView) findViewById(R.id.listchilds); 

    int[] colors = { 0xFFDAD7CE, 0xFFF9F8F5, 0 }; 
    listView.setDivider(new GradientDrawable(Orientation.TOP_BOTTOM, colors)); 
    listView.setDividerHeight(2);