我有一個ListView
與ImageView
覆蓋行。 (我正在用畢加索加載圖片,我曾嘗試滑行,但畢加索略快)它在棒棒糖和kitkat上足夠流暢,但在棉花糖上,滾動速度變得非常慢,有時會得到ANR消息。ListView滾動棉花糖變得緩慢與圖像
這裏是我的列表項的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/img_genre_bg"
android:scaleType="fitXY"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--android:background="@color/trans_black"-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img_play"
android:layout_centerHorizontal="true"
android:src="@drawable/play_button"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_genre_name"
android:textSize="20sp"
android:textAllCaps="true"
android:layout_centerHorizontal="true"
android:textColor="@color/white"
android:layout_below="@+id/img_play"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_genre_id"
android:visibility="gone"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@color/colorAccent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
列表視圖:
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv_genre"
android:scrollbars="none"
android:divider="@null"
android:cacheColorHint="@android:color/transparent"
android:fastScrollEnabled="true"
android:persistentDrawingCache="scrolling"
android:scrollingCache="false">
</ListView>
getView():
public View getView(int position, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowview=view;
if(rowview==null){
rowview=inflater.inflate(R.layout.item_genre_list,viewGroup,false);
}
id = (TextView) rowview.findViewById(R.id.tv_genre_id);
TextView name = (TextView) rowview.findViewById(R.id.tv_genre_name);
ImageView img_genre_bg = (ImageView) rowview.findViewById(R.id.img_genre_bg);
ImageView img_play = (ImageView) rowview.findViewById(R.id.img_play);
opensans = Typeface.createFromAsset(context.getAssets(), "font/OpenSans-Light.ttf");
name.setTypeface(opensans);
GENRE genre=new GENRE();
genre=genres.get(position);
id.setText(genre.getGenre_id());
name.setText(genre.getGenre_name());
Picasso
.with(context)
.load(genre.getGenre_image())
.placeholder(R.drawable.loading)
.into(img_genre_bg);
return rowview;
}
我曾嘗試加載單獨的AsyncTask
線程上的圖像,但它仍然卡在滾動。將其更改爲RecyclerView
也沒有幫助。
您沒有在創建每一行時使用'ViewHolder'模式並創建字體 – kId