在 android 中的 Recycler-View 上添加图像时,滚动视图无法正确滚动
Scroll-view not scrolling properly when add images on Recycler-View in android
您好,当我在 Recycler-View 中添加多个图像时,我在滚动视图中插入了 Recycler-View,然后滚动视图无法正确滚动,一段时间后它会自动崩溃,我认为这是图像高分辨率问题,有人可以吗请帮助我
代码:-
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getActivity().getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, Constants.CAMERA_REQUEST_CODE);
thumbnail = Bitmap.createScaledBitmap(BitmapFactory.decodeFile("" + shopImageFile),
100, 100, true);
shop_image.setImageBitmap(thumbnail);
Utilities.setEmptyError(business_name_layout);
setImageMargins(shop_image);
xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:layout_marginLeft="16dp"
android:layout_marginTop="3dp" />
</Scrollview>
始终在工作线程上执行复杂操作或使用 AsyncTask
,如
在你的 Adapter
下面添加 class
static class ImageLoader extends AsyncTask<>{
private ImageView shop_image;
ImageLoader(ImageView shop_image){
this.shop_image = shop_image;
}
..
public Bitmap doInBackground(){
return Bitmap.createScaledBitmap(BitmapFactory.decodeFile("" + shopImageFile),
100, 100, true);
}
public void onPostExecute(Bitmap thumbnail){
shop_image.setImageBitmap(thumbnail);
Utilities.setEmptyError(business_name_layout);
setImageMargins(shop_image);
}
..
}
在 Bind Holder 方法中
new ImageLoader().execute();
您好,当我在 Recycler-View 中添加多个图像时,我在滚动视图中插入了 Recycler-View,然后滚动视图无法正确滚动,一段时间后它会自动崩溃,我认为这是图像高分辨率问题,有人可以吗请帮助我
代码:-
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getActivity().getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, Constants.CAMERA_REQUEST_CODE);
thumbnail = Bitmap.createScaledBitmap(BitmapFactory.decodeFile("" + shopImageFile),
100, 100, true);
shop_image.setImageBitmap(thumbnail);
Utilities.setEmptyError(business_name_layout);
setImageMargins(shop_image);
xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:layout_marginLeft="16dp"
android:layout_marginTop="3dp" />
</Scrollview>
始终在工作线程上执行复杂操作或使用 AsyncTask
,如
在你的 Adapter
下面添加 class
static class ImageLoader extends AsyncTask<>{
private ImageView shop_image;
ImageLoader(ImageView shop_image){
this.shop_image = shop_image;
}
..
public Bitmap doInBackground(){
return Bitmap.createScaledBitmap(BitmapFactory.decodeFile("" + shopImageFile),
100, 100, true);
}
public void onPostExecute(Bitmap thumbnail){
shop_image.setImageBitmap(thumbnail);
Utilities.setEmptyError(business_name_layout);
setImageMargins(shop_image);
}
..
}
在 Bind Holder 方法中
new ImageLoader().execute();