2016-11-01 1 views
0

ListView에 행을 덮는 ImageView이 있습니다. (나는 Picasso로 이미지를로드하고 있는데, 우선 글라이딩을 시도했지만 Picasso가 약간 빠름) 롤리팝과 kitkat에서 원활하게 작동하지만 marshmallow에서 스크롤이 매우 느리게 진행되고 ANR 메시지가 표시되는 경우가 있습니다.ListView scroll in marshmallow 이미지가 느려짐

<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() :

다음은 목록 항목에 대한 내 XML이다

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으로 변경해도 도움이되지 않았습니다.

+0

당신은'ViewHolder' 패턴을 사용하지 않고 모든 행이 생성되는 동안 서체를 생성합니다. – kId

답변

1

행이 생성 될 때마다 Typeface을 생성하기 때문입니다. 행이 생성 될 때마다 Asset을 생성하는 오버 헤드로 인해 실행 속도가 느려질 수 있습니다.

이 코드를 클래스의 Constructor으로 이동하십시오.

name.setTypeface(opensans); 

더 효율적으로 ListView 이상의 메모리를 관리하기 때문에 더 적합 RecyclerView로 이동하는 것이 좋습니다 :

opensans = Typeface.createFromAsset(context.getAssets(), "font/OpenSans-Light.ttf"); 

그런 다음 당신은 이미 생성 된 유형을 사용할 수 있습니다.

+0

좋아,했는데 속도 문제에별로 변하지 않았습니다. –

+1

또한'ViewHolder' 패턴을 사용해야합니다. 각 행에 새 뷰를 작성 중입니다. 이 예제는'ViewHolder' 사용법을 보여줍니다 : https://dzone.com/articles/optimizing-your-listview –