android listView滚动时隔行出现墨色分割线
android listView滚动时隔行出现黑色分割线
近日在做android应用时,出现了一个很小但容易忽视的问题。ListView滚动时隔行出现分割线,分割线的出现影响了界面的美观,经过排除后发现是一个细节问题引起。
listview未滚动时,如下图:
listview滚动时出现,如下图
也许你以为使用 android:cacheColorHint="#00000000"能解决问题,其实不然。再次使用setDivider(null);问题仍然没有解决。
其实这个问题是由item引起,与listView的属性无关。
原来item的代码如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:background="@drawable/filelist_item_bg" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/msglist_item_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/msg_icon" > </ImageView> </RelativeLayout> <TextView android:id="@+id/msglist_item_msg_title" android:layout_width="270dip" android:layout_height="40dip" android:layout_marginLeft="10dip" android:layout_marginTop="2dip" android:layout_weight="0.23" android:singleLine="true" android:textColor="#000000" android:textSize="18dip" /> </LinearLayout> </LinearLayout>
上面
android:background="@drawable/filelist_item_bg"
使用selector设置背景。正是背景的位置引起了上述隔行分割线的出现。将
android:background="@drawable/filelist_item_bg"
代码移到下面的LinearLayout后,问题终于解决。