我正在显示设备存储中的所有图像。
问题是当我向上滚动时它并不平滑(介于两者之间)。
我正在使用etsy/AndroidStaggeredGrid并使用以下代码:
public class GalleryFragment extends Fragment {
StaggeredGridView gridview;
ArrayList<Gallery> galleries;
CameraGalleryAdapter gallerylist;
String[] arrPath;
String[] videoPath;
int count,count2,count3,count4;
ProgressBar progressBar;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_gallery, container, false);
galleries=new ArrayList<Gallery>();
((ActionBarActivity) getActivity()).getSupportActionBar().show();
gridview = (StaggeredGridView)rootView.findViewById(R.id.gridcamera);
progressBar=(ProgressBar)rootView.findViewById(R.id.progressBar);
gallerylist=new CameraGalleryAdapter(getActivity().getApplicationContext(),R.layout.gallery_grid,galleries);
gridview.setAdapter(gallerylist);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Fragment currentFragment = new PreviewFragment();
Bundle args = new Bundle();
// CameraActivity.isGalleryFrgament=false;
if (galleries.get(i).getIsImage()) {
args.putString("imagepath", galleries.get(i).getImageUrl());
args.putString("isVideo", "gallery");
} else {
args.putString("isVideo", "videogallery");
args.putString("fileUri", galleries.get(i).getVideoUrl());
}
currentFragment.setArguments(args);
FragmentManager frgManager;
frgManager = getActivity().getSupportFragmentManager();
frgManager.beginTransaction().replace(R.id.camera_container, currentFragment).addToBackStack("tag").commit();
}
});
getImages();
return rootView;
}
private void getImages()
{
((CameraActivity)getActivity()).setOnBackPressedListener(new BaseBackPressedListener(getActivity(),true));
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID,MediaStore.Video.Media.DATA,
};
final String orderBy = MediaStore.Images.Media._ID;
Cursor cursor = getActivity().getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
count = cursor.getCount();
Cursor cursor2 = getActivity().getContentResolver().query(
MediaStore.Images.Media.INTERNAL_CONTENT_URI, columns, null,
null, orderBy);
count2 = cursor2.getCount();
Cursor cursor3 = getActivity().getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
count3 = cursor3.getCount();
Cursor cursor4 = getActivity().getContentResolver().query(
MediaStore.Video.Media.INTERNAL_CONTENT_URI, columns, null,
null, orderBy);
count4 = cursor4.getCount();
arrPath = new String[count+count2+ count3+count4];
videoPath= new String[count+count2+ count3+count4];
for (int i = 0; i < count; i++)
{
cursor.moveToPosition(i);
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
Gallery ga=new Gallery();
ga.setImageUrl(cursor.getString(dataColumnIndex));
ga.setIsImage(true);
galleries.add(ga);
}
for (int i = 0; i < count2; i++)
{
cursor2.moveToPosition(i);
int dataColumnIndex = cursor2.getColumnIndex(MediaStore.Images.Media.DATA);
Gallery ga=new Gallery();;
ga.setImageUrl(cursor2.getString(dataColumnIndex));
ga.setIsImage(true);
galleries.add(ga);
}
for (int i = 0; i < count3; i++)
{
cursor3.moveToPosition(i);
int dataColumnIndex = cursor3.getColumnIndex(MediaStore.Video.Media.DATA);
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(cursor3.getString(dataColumnIndex),
MediaStore.Images.Thumbnails.MINI_KIND);
Gallery ga=new Gallery();
ga.setVideoThumbnail(thumb);
ga.setVideoUrl(cursor3.getString(dataColumnIndex));
ga.setIsImage(false);
galleries.add(ga);
}
for (int i = 0; i < count4; i++)
{
cursor4.moveToPosition(i);
int dataColumnIndex = cursor4.getColumnIndex(MediaStore.Video.Media.DATA);
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(cursor4.getString(dataColumnIndex),MediaStore.Images.Thumbnails.MINI_KIND);
Gallery ga = new Gallery();
ga.setVideoThumbnail(thumb);
ga.setVideoUrl(cursor4.getString(dataColumnIndex));
ga.setIsImage(false);
galleries.add(ga);
}
}
}
如何提高向上滚动的速度并使其流畅?