设置listview的adapter时,item下面的下划线有高有低,部分左右有缩进,部分完全填充宽度

来源:互联网 发布:php无组件上传类 编辑:程序博客网 时间:2024/05/16 03:46

1,listview的布局如下

<ListView

        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:divider="@null"/>

2,在adapter的getview()中,其中的item布局下划线布局

<View
        android:id="@+id/line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/list_split_line_color" />


       if (position==1||position==2){//item1和item2下的下划线宽变高
                ViewGroup.LayoutParams params= line.getLayoutParams();
                params.height=10;
                line.setLayoutParams(params);
           
        }else{//必须设置,不然会在item0下画一条高为10的线,不知这是不是内部 bug
            int marginLR=(int)parent.getContext().getResources().getDimension(R.dimen.widget_margin_14);//自定义的边距
            ViewGroup.LayoutParams params= line.getLayoutParams();
            params.height=1;//将其他线的高设置为1
            UiUtils.setMargins(line,marginLR, 0, marginLR, 0);
        }

3,在activity中

  ......ListView listview=(ListView)findById(R.id.listview);

        MyAdapter adapter=new MyAdapater();

        listview.setAdapater(adapter);

  ........


效果见图



0 0
原创粉丝点击