歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 之listview的優化

Android 之listview的優化

日期:2017/3/1 10:50:57   编辑:Linux編程

一開始剛接觸Android開發的人在使用listview的時候都會一般覺得android系統 默認的listview的界面效果不是很好,首先,他的整體都是黑色的,如果給它添加一個背景圖片作為修飾的話,在listview滑動的時候會產生黑色的背景遮住了背景圖片,讓界面效果不是很好。其二,listview帶有分割線,在對像iphone的一些界面進行模仿的時候,看上去是有別扭的,那該如何去去除它們,本文就對這些問題進行了一些簡單的處理。

下面是一個listview的布局

  1. <ListView
  2. android:scrollbars="none"
  3. android:background="@color/listbg"
  4. android:divider="@color/listbg"
  5. android:layout_marginLeft="20dip"
  6. android:layout_marginRight="20dip"
  7. android:id="@+id/context"
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:cacheColorHint="#00000000"
  11. android:layout_gravity="center"
  12. android:listSelector="@drawable/timer_list_selector"
  13. />

timer_list_selector.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3. <item android:state_selected="true" android:drawable="@android:color/transparent" />
  4. </selector>

其中listbg和transparent的值為

<color name="transparent">#50000000</color>
<color name="listbg" >#FFFFFF</color>

而在設置過程中較為主要的屬性是

android:cacheColorHint="#00000000"

這樣便能優化你的listview界面效果。

Copyright © Linux教程網 All Rights Reserved