滚动时ListView非常慢

时间:2016-10-19 21:42:57

标签: android performance listview

我真的需要帮助,我在我的应用程序中使用的Listview在滚动时非常慢,我该如何解决?我减少了图像,使用了视图,但没有任何改变..

我是android的初学者:)

也得到这样的信息:I / Choreographer:跳过32帧!应用程序可能在其主线程上做了太多工作。

这是我的代码

public class asker extends Activity {
    ListView list;
    String[] askerbaslik;
    int[] images =

            {R.drawable.barbar_icon, R.drawable.okcu_icon,
                    R.drawable.dev_icon,
                    R.drawable.goblin_icon,
                    R.drawable.duvar_kirici_icon, R.drawable.balon_icon,
                    R.drawable.buyucu_icon, R.drawable.sifaci_icon,
                    R.drawable.ejderha_icon,
                    R.drawable.pekka_icon, R.drawable.yavruejder_icon, R.drawable.madenci_icon};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);

        Resources res = getResources();
        askerbaslik = res.getStringArray(R.array.asker_adlari);

        list = (ListView) findViewById(R.id.listview);

        ilyasadapter adapter = new ilyasadapter(this, askerbaslik, images);

        list.setAdapter(adapter);
    }

    class ilyasadapter extends ArrayAdapter<String> {
        Context context;
        int[] images;
        String[] titlearray;

        ilyasadapter(Context c, String[] titles, int imgs[]) {
            super(c, R.layout.liste_tasarim, R.id.asker_baslik, titles);
            this.context = c;
            this.images = imgs;
            this.titlearray = titles;
        }

        class MyViewHolder {
            TextView mytitle;
            ImageView myimage;

            MyViewHolder(View v) {

                mytitle = (TextView) v.findViewById(R.id.asker_baslik);
                myimage = (ImageView) v.findViewById(R.id.asker_icon);
            }
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            MyViewHolder holder = null;

            if (row == null) {

                LayoutInflater inflater = (LayoutInflater)
                        context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
                row = inflater.inflate(R.layout.liste_tasarim, parent, false);
                holder = new MyViewHolder(row);

                row.setTag(holder);

                Log.d("test", "creating a new row");
            } else {

                holder = (MyViewHolder) row.getTag();

                Log.d("test", "Recycling stuff");
            }

            holder.myimage.setImageResource(images[position]);
            holder.mytitle.setText(titlearray[position]);

            return row;
        }
    }
}

单行文件

<?xml version="1.0" encoding="utf-8"?>

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">


<ImageView
    android:layout_marginTop="5dp"
    android:id="@+id/asker_icon"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/barbar_icon"
    android:background="@drawable/rounded_corner"

    ></ImageView>

<TextView
    android:id="@+id/asker_baslik"
    android:layout_marginTop="40dp"
    android:layout_marginLeft="30dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Asker ismi"
    android:textColor="#ffffff"
    android:textSize="15dp"
    android:fontFamily="sans-serif"
    />

  </LinearLayout>

我的列表视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#455A64" >
<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#263238"
    android:dividerHeight="2px"
    />
 </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

请尝试从列表视图中删除图标,看看是否可以提高性能。您可能正在使用分辨率太高的图像。在使用高分辨率图像时,我也注意到performance anomalies

如果有帮助,请告诉我。如果没有,我们可以尝试其他一些事情。