在使用adapter listview的时候,系统会自动加上一条分割线,有时候会觉得很难看,把dividerHeigth这个高度设置为0都是不可以的,但是在xml中把divider这个属性设置为空就搞掂啦~
- <ListView
- android:id="@+id/commentListView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fadingEdge="none"
- android:cacheColorHint="@null"
- android:divider="@null"
- android:layout_margin="5dip">
- </ListView>
然后又发现了另一种情况,为什么把margin设置了5个dip,但是没效果?问题是你设置的是整个listview的边界,而不是每个item的边界,
这样的话我暂时还没找到可以用一句代码可以控制的,但是还是有办法可以解决,就是在item外面再套一个relativelayout,里面设置padding。
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:paddingTop="5dip">
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="65dip"
- android:padding="5dip"
- android:layout_centerVertical="true"
- android:background="@color/whitesmoke">
- <ImageView
- android:id="@+id/account_img"
- android:layout_width="45dp"
- android:layout_height="45dp"
- android:scaleType="centerCrop"
- android:layout_marginLeft="@dimen/header_img_margin_left"
- android:src="@drawable/account_avatar" />
- <TextView
- android:id="@+id/account_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/account_img"
- android:layout_alignParentTop="true"
- android:padding="2dp"
- android:textSize="20dip"
- android:text="kam"
- android:textColor="@android:color/black" />
- <TextView
- android:id="@+id/account_contents"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@id/account_name"
- android:layout_alignLeft="@id/account_name"
- android:padding="2dp"
- android:textSize="@dimen/text_size"
- android:text="so cool~"
- android:textColor="@color/gray" />
- <TextView
- android:id="@+id/comment_time"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentRight="true"
- android:padding="2dp"
- android:textSize="@dimen/text_size"
- android:layout_marginRight="@dimen/header_img_margin_left"
- android:text="1 hour ago"
- android:textColor="@color/gray" />
- </RelativeLayout>
- </RelativeLayout>