2013-03-18 44 views
1

我試圖在同一時間如何在同一時間

enter image description here

會對我的列表視圖外,並用不同的顏色每隔一行添加邊框邊框ListView和不同行的顏色

這裏是從我的適配器getView方法

 viewHolder.dateView.setText(entry.getDateString("yyyy-MM-dd HH:mm")); 
     if(position % 2 == 0){ 
      viewHolder.linearLayout.setBackgroundResource(R.color.grey); 

     } 
     else{ 
      //viewHolder.linearLayout.setBackgroundResource(R.color.white); 
     } 

這裏是我使用,使在列表視圖不是小區邊界的xml文件

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
    <!-- use this for transparent --> 
    <!-- <solid android:color="#00000000" /> --> 
    <!-- use this for a background colour --> 
    <solid android:color="@color/white" /> 
    <stroke android:width="2dip" android:color="@color/black"/> 
</shape> 

如果我設置底色爲細胞它,我再也看不到邊框

回答

5

重寫

你明明寫着:How do you put a border around a ListView?因爲你正在使用從更好/更受歡迎代碼回答。不過看過底部的答案,以及,我不得不通過增加2dp填充成功

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/border_listview" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    android:padding="2dp" > 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="@null" 
     android:dividerHeight="0dp" /> 
</LinearLayout> 
+0

這仍然會刪除我的境界(相同的寬度爲界):/ – 2013-03-19 09:15:57

+0

我改變了我的答案。 – Sam 2013-03-19 20:07:01

+0

謝謝,我設法達到了我想要的效果,我認爲這就是你剛纔的建議或者沿着這條線,我會將我的代碼添加到你的帖子中以幫助未來的其他人:) – 2013-03-19 20:24:12