2013-03-18 46 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