应用程序抽屉(RecyclerView网格)滚动速度不快

时间:2017-03-22 10:10:34

标签: android

我的App抽屉里有我设备的所有应用程序,我使用的是RecylerView。有4列有应用程序图标,应用程序名称有一个RecylerView项。但它不像RecylerView那样快速滚动像像素或nova Launcher app抽屉。 这是我的来源。我按包名获取Icon。请建议我解决。

RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 4);
    appDrawerRecyclerView.setLayoutManager(layoutManager);
    gridAppDrawer = new GridAppDrawer(getContext(), applications, resArray, R.layout.item_app_drawer_pixel);
    appDrawerRecyclerView.setAdapter(gridAppDrawer);

适配器源

public class GridAppDrawer extends RecyclerView.Adapter<GridAppDrawer.ViewHolder> {
int[] res;
int fragNo;
Context cntx;
List<RelatedAppsModeInfo> apps;
ArrayList<String> arraylist;
int layout;

public GridAppDrawer(Context mContext, List<RelatedAppsModeInfo> mApps, int[] mRes, int mLayout) {
    this.cntx = mContext;
    apps = mApps;
    res = mRes;
    layout = mLayout;
    this.arraylist = new ArrayList<String>();
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_app_drawer_pixel, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    try {
        holder.titleText.setText(apps.get(position).related_app_name);
        holder.image.setImageDrawable(cntx.getPackageManager().getApplicationIcon(apps.get(position).related_apps_pkg_name));
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PackageManager pm = cntx.getPackageManager();
                RecentAppsModeInfo recentAppsPbj = new RecentAppsModeInfo();
                recentAppsPbj.setRecentAppsInfo(0, apps.get(position).related_apps_pkg_name, apps.get(position).related_app_name);
                Intent launchIntent = pm.getLaunchIntentForPackage(apps.get(position).related_apps_pkg_name);
                cntx.startActivity(launchIntent);
            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
public int getItemCount() {
    return apps.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
    private TextView titleText;
    private ImageView image;

    public ViewHolder(View view) {
        super(view);

        titleText = (TextView) view.findViewById(R.id.item_title);
        image = (ImageView) view.findViewById(R.id.item_img);
    }
}

}

0 个答案:

没有答案