GridView - 滚动不顺畅

时间:2017-05-07 10:44:30

标签: android gridview getview

在我的应用程序中,我正在从其URL加载图像(16张图像),但在GridView中加载图像后,滚动不顺畅。在某些设备中这是我不明白的事情,我正在使用 Glide Library 我已经尝试过使用:

android:fastScrollEnabled="true"
 android:smoothScrollbar="true"

但没有任何事情滚动仍然不顺利。

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    final ArrayList<String> movieList =  new ArrayList<>();
    /*Source*/
    movieList.add("https://i.imgur.com/KAoAPcY.jpg");
    ......
    /*****/
    View v =  inflater.inflate(R.layout.fragment_art, container, false);
    myGrid = (GridView) v.findViewById(R.id.gridViewCategory);
    myGrid.setFastScrollEnabled(true);
    adapter = new CategoryAdapter(getActivity(), movieList);
    myGrid.setAdapter(adapter);
    myGrid.setSmoothScrollbarEnabled(true);
    myGrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Intent popup = new Intent(getActivity(), Pop.class);
                    popup.putExtra("WallpaperURL", movieList.get(position));
                    startActivity(popup);
        }
        });
       return v;
   }
}
  class CategoryAdapter extends BaseAdapter {
     private Context context;
     private ArrayList<String> imageId= new ArrayList<>();
    CategoryAdapter(Context context,ArrayList<String> imageId){
         this.context=context;
         this.imageId=imageId;
}
@Override
public int getCount() {
    return imageId.size();
}

@Override
public Object getItem(int position) {
    return imageId.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}
private class ViewHolder{
    ImageView CategoryImage;
    ViewHolder(View view){
        CategoryImage = (ImageView) view.findViewById(R.id.cat_imageView);
    }
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //View row = convertView;
    ViewHolder holder;
    convertView = null;
    if(convertView == null){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.picture_item, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
        final ProgressBar progressBar = (ProgressBar) convertView.findViewById(R.id.progress);
        Glide.with(context)
                .load(imageId.get(position))
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                        progressBar.setVisibility(View.GONE);
                        return false;
                    }
                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        progressBar.setVisibility(View.GONE);
                        return false;
                    }
                })
                .into(holder.CategoryImage);
    }
    else{
        holder = (ViewHolder) convertView.getTag();
    }
    return convertView ;
}

1 个答案:

答案 0 :(得分:0)

我在manifest.xml中添加了android:hardwareAccelerated="true"