recyclelerView中的SharedElementTransition位滞后

时间:2017-11-20 07:34:42

标签: android

我已经实现了将recyclerview中的元素转换共享到详细activity所需的行为,但在点击行项目时观察到了轻微的烦人延迟。这是一个片段,正在共享图像。

 public void onRowClick(int position, View view, ImageView sharedImv) {
    System.out.println("hehe + position : " + position);

    NoteModel noteModel = noteModelList.get(position);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), noteModel.getPath());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
    byte byteArray[] = byteArrayOutputStream.toByteArray();
    Intent intent = new Intent(v.getContext(), DetailedActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString("key", "senpai");
    bundle.putString(EXTRA_ANIMAL_IMAGE_TRANSITION_NAME, ViewCompat.getTransitionName(sharedImv));
    bundle.putByteArray("picture", byteArray);
    intent.putExtras(bundle);
    ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(getActivity(),
            sharedImv, ViewCompat.getTransitionName(sharedImv));
    startActivity(intent, activityOptions.toBundle());
}

DetailedActivityClass

 if (bundle != null) {
        String key = bundle.getString("key");
        String imvTransitionName = bundle.getString(FragOne.EXTRA_ANIMAL_IMAGE_TRANSITION_NAME);
        imv2.setTransitionName(imvTransitionName);


        byte byteArray[] = bundle.getByteArray("picture");

        if (byteArray != null) {
            System.out.println(key + imvTransitionName);
            Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);


            Glide.with(getApplicationContext()).asBitmap().load(bitmap).listener(new RequestListener<Bitmap>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                    supportStartPostponedEnterTransition();
                    return false;
                }

                @Override
                public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                    supportStartPostponedEnterTransition();
                    return false;
                }
            }).into(imv2);
        }

这是适配器类:

@Override
public void onBindViewHolder(MyViewHolder myViewHolder, final int position) {
    System.out.println("OBV");
    if (v != null) {

        NoteModel noteModel = noteModelList.get(position);
        myViewHolder.noteRowTextView.setText(noteModel.getTitle());
        Glide.with(v.getContext()).load(noteModel.getPath()).into(myViewHolder.imageView);
        ViewCompat.setTransitionName(myViewHolder.imageView, "imageViewTransName");
    }

}

1 个答案:

答案 0 :(得分:0)

哈哈,我刚刚删除了所有这些位图操作并简单地实现了parcelable并提供了drawable的路径,现在它很好。发生了。