Recycler View用三个大图像滚动缓慢,我该如何解决这个问题?

时间:2015-10-23 13:39:01

标签: android android-recyclerview

我的回收站视图运行良好,它加载了三个图像,但图像质量很高(每个图像大约500kb),导致滚动滞后。 那么如何让我的适配器用于回收器视图有效地将图像加载到ImageView,以便我的应用程序不会跳过帧并导致滚动滞后?

这是我的适配器看起来的样子,

package com.erbowl.erbowlbeta;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by nucogroup on 10/22/2015.
 */
public class dashboardItemsAdapter extends RecyclerView.Adapter<dashboardItemsAdapter.dashboardItemsViewHolder>{

    DashboardItem[] mDashboardItems;
    public dashboardItemsAdapter(DashboardItem[] dashboardItems){
        mDashboardItems = dashboardItems;
    }

    @Override
    public dashboardItemsViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.dashboard_list_item, viewGroup, false);

        dashboardItemsViewHolder viewHolder = new dashboardItemsViewHolder(view);

       return viewHolder;
    }

    @Override
    public void onBindViewHolder(dashboardItemsViewHolder dashboardItemsViewHolder, int i) {
                dashboardItemsViewHolder.bindItem(mDashboardItems[i]);
    }

    @Override
    public int getItemCount() {
        return mDashboardItems.length;
    }

    public class dashboardItemsViewHolder extends RecyclerView.ViewHolder {

        public ImageView itemImage;
        public TextView mTexttext;

        public dashboardItemsViewHolder(View itemView) {
            super(itemView);
          itemImage = (ImageView) itemView.findViewById(R.id.itemImage);
          mTexttext = (TextView) itemView.findViewById(R.id.strainTT);
        }

        public void bindItem(DashboardItem dashboardItem){

            itemImage.setDrawingCacheEnabled(false);
            itemImage.setImageResource(dashboardItem.getmMainImage());
            mTexttext.setText(dashboardItem.getmTitle());
        }
    }


}

Here's what the ui interface of the three images looks like

0 个答案:

没有答案