简体   繁体   English

在Android中的Recycler-View上添加图像时,滚动视图无法正确滚动

[英]Scroll-view not scrolling properly when add images on Recycler-View in android

Hi I have inserted Recycler-View inside scroll-view when i added multiple images inside Recycler-View then scroll view is not scrolling properly and after some time it's crashing automatically and i think it's images high resolution problem can some one help me please 嗨,我在Recycler-View中插入了多个Recycler-View时,在Recycler-View中添加了多个图像,然后滚动视图无法正确滚动,过了一段时间它自动崩溃了,我认为这是图像的高分辨率问题,有人可以帮帮我吗

code:- 码:-

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:

<?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>

Always do complex operations on worker thread or use AsyncTask as in 始终在工作线程上执行复杂的操作,或使用AsyncTask

In your Adapter add below class 在您的Adapter添加下面的类

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);
    }
 ..
}

In Bind Holder method 在绑定持有人方法中

new ImageLoader().execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM