近日在做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后,问题终于解决。



更多相关文章

  1. 全面了解Android热修复技术
  2. Flutter(三):实现Flutter代码调用Android原生代码(创建WebView Plu
  3. Android(安卓)配置PhoneGap开发环境
  4. Android启动脚本init.rc分析
  5. Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高
  6. 关于Android(安卓)Force Close 出现的原因 以及解决方法
  7. android.graphics.Movie
  8. LatinIME输入法分析
  9. MVP+RxJava+Dagger打造的Android(安卓)Album

随机推荐

  1. Android(Java):Android jni学习(二)
  2. android linux alsa_amixer
  3. Android 中compiledSDKVersion,minSdkVer
  4. android studio release版本下打印输出日
  5. Android设置StatusBar颜色
  6. cocoscreator构建的android工程报错
  7. ADT-abundle-使用过程中不断出现的错误
  8. 关于Android自定义相机进行拍照(小米手机
  9. android: 不需要焦点的TextView跑马灯 Ma
  10. Android XMl写入