android listView滚动时隔行出现黑色分割线
16lz
2021-01-24
近日在做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后,问题终于解决。
更多相关文章
- 全面了解Android热修复技术
- Flutter(三):实现Flutter代码调用Android原生代码(创建WebView Plu
- Android(安卓)配置PhoneGap开发环境
- Android启动脚本init.rc分析
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高
- 关于Android(安卓)Force Close 出现的原因 以及解决方法
- android.graphics.Movie
- LatinIME输入法分析
- MVP+RxJava+Dagger打造的Android(安卓)Album