如何添加边框ListView和不同行的颜色,同时 [英] How to add border to listview and different row colors at the same time

查看:278
本文介绍了如何添加边框ListView和不同行的颜色,同时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个边界在我的列表视图的外面和不同的颜色每隔一行在同一时间

I'm trying to have a border on the outside of my listview and a different color for every other row at the same time

这里的getView方法,从我的适配器

here's the getView method from my adapter

        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文件而不是细胞

here's the xml file which I use to make the border on the listview not the cell

<?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>

如果我设置底色为细胞它,我再也看不到边框

if I set the backround to the cell it I can no longer see the border

推荐答案

重写

您已经阅读明显:你怎么把一个边框一个ListView ,因为你使用的是$ C $? c从更好/更受欢迎的答案。但阅读的底部答案好,我有成功加入 2DP 填充(相同的宽度为界。)

You have obviously read: How do you put a border around a ListView? since you are using the code from the better / more popular answer. But read the bottom answer as well, I had success by adding 2dp padding (the same width as the border.)

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

这篇关于如何添加边框ListView和不同行的颜色,同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆