2014-04-18 25 views
0

我有一個listview具有的項目,我喜歡這個定義一些花哨的陰影背景:列表視圖與具有繪製背景的項目有表現不佳

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Drop Shadow Stack --> 
    <item> 
     <shape> 
      <padding android:top="1.2dp" android:right="1.2dp" android:bottom="1.2dp" android:left="1.2dp" /> 
      <solid android:color="#02000000" /> 
      <corners android:radius="8dp" /> 

     </shape> 
    </item> 
    <item> 
     <shape> 
      <padding android:top="1.2dp" android:right="1.2dp" android:bottom="1.2dp" android:left="1.2dp" /> 
      <solid android:color="#05000000" /> 
      <corners android:radius="7dp" /> 
     </shape> 
    </item> 
</layer-list> 

這工作是好的,但把它當成背景列表視圖的項目使得它的性能變差減慢。對於我定義我的item.xml,這是背景的項目(不textviews,圖像):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/drop_shadow" 
    android:orientation="horizontal" 
    > 

如果我設置了android:背景值的顏色,它工作正常,那麼問題肯定是每當listview刷新時,它必須加載drop_shadow .xml drawable。 我的問題是,如果它可以以某種方式進行優化?例如,與在項目中使用自定義字體的情況相同,我必須創建一個TypefaceCahce並從中加載字體,所以只需要在每次列表視圖刷新時加載一次。是否有類似的drawables解決方案?

+0

可以添加你是如何獲得在列表視圖適配器的意見。 – mha90

回答

0

嘗試在你的ListView XML添加這些:

android:scrollingCache="false" 
android:animationCache="false" 
相關問題