0
  private class CustomPagerAdapter extends PagerAdapter {
        private Context mContext;
        private LayoutInflater mLayoutInflater;
        private ImageView displayArt;
        private ImageView songImage;
        private TextView playerName;

        private CustomPagerAdapter(Context context) {
            mContext = context;
            mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        @Override
        public int getCount() {
            return songList.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View itemView = mLayoutInflater.inflate(R.layout.adapter_audio_player, container, false);
            FieldIntialization(itemView);
            updatePlayerView(position);
            container.addView(itemView);
            return itemView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((RelativeLayout) object);
        }

        private void FieldIntialization(View view) {
            displayArt = (ImageView) view.findViewById(R.id.songImage);
            songImage = (ImageView) view.findViewById(R.id.songDisplayArt);
            playerName = (TextView) view.findViewById(R.id.songName);
        }

        @Override
        public int getItemPosition(Object object) {
            return PagerAdapter.POSITION_NONE;
        }

        private void updatePlayerView(int songIndex) {
            playerName.setText(songList.get(songIndex).getPlayerTitle());
            displayArt.setScaleType(ImageView.ScaleType.FIT_XY);

            final String contentURI = "content://media/external/audio/media/" + songList.get(songIndex).getPlayerId() + "/albumart";

            Glide.with(getApplicationContext()).load(contentURI).dontAnimate().
                    error(R.drawable.music_player_background)
                    .bitmapTransform(new BlurTransformation(getApplicationContext()))
                    .into(displayArt);


            songImage.setScaleType(ImageView.ScaleType.FIT_XY);
            Bitmap originalBitmap = null;
            try {
                originalBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), Constants.getDefaultAlbumUri(
                        String.valueOf(songList.get(songIndex).getPlayerAlbumId())
                ));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if ((originalBitmap == null || originalBitmap.equals(""))) {
                Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.no_photo);
                RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.create(getResources(), largeIcon);
                roundDrawable.setCircular(true);
                songImage.setImageDrawable(roundDrawable);

            } else {
                RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.create(getResources(), originalBitmap);
                roundDrawable.setCircular(true);
                songImage.setImageDrawable(roundDrawable);
            }


        }
    }

我必须将模糊图像显示为带有圆形图像的背景。我已经完成了上面的操作。当我滑动 viewpager 时它会滞后。我使用滑行显示图像。请任何人给我一个解决方案。在此先感谢

4

1 回答 1

1

模糊是一个 CPU 密集型过程。由于 viewpager 为相邻视图创建视图,因此需要花费太多时间来处理和创建滞后。特别是在较旧的设备和较少的 RAM 中,您将面临更多问题。

对于圆角图像,如果你需要使用圆形图像使用 CircleImageView,否则只用于圆角,你可以使用这个

于 2017-04-24T06:20:01.123 回答