缩放ImageView活动之间的过渡

时间:2016-08-19 07:00:51

标签: android

我尝试在两个活动之间创建共享ImageView(例如,从活动A到活动B)。 问题出在这个步骤之后:

  1. 图片已分享到活动
  2. 图片放大了活动B;
  3. 从B活动回到A;
  4. 观看this视频
  5. 没有缩放就没有问题:您可以观看this

    我的风格-v21:

    <style name="AppTheme.NoActionBar" >
        <item name="android:colorEdgeEffect">@color/primary</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:buttonStyle">@style/MyButtonStyle</item>
    
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowExitTransition">@android:transition/explode</item>
    
        <item name="android:windowSharedElementEnterTransition">@transition/change_image_transform</item>
        <item name="android:windowSharedElementExitTransition">@transition/change_image_transform</item>
    </style>
    

    我的转型:

    <?xml version="1.0" encoding="utf-8"?>
    <transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <changeImageTransform/>
    </transitionSet>
    

    我的ImageActivity:

    public class ImageActivity extends AppCompatActivity {
    
    public static String IMAGE_URL = "image_url";
    public static String TEXT = "text";
    private ProgressBar spinner;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(android.R.transition.move));
        }
    
        setContentView(R.layout.activity_image);
    
        ImageView image = (ImageView) findViewById(R.id.image);
        TextView tvName = (TextView) findViewById(R.id.tvName);
        spinner = (ProgressBar) findViewById(R.id.pbLoading);
    
        String imageUrl = getIntent().getStringExtra(IMAGE_URL);
        String text = getIntent().getStringExtra(TEXT);
    
        if (text != null)
            tvName.setText(text);
        else tvName.setVisibility(View.GONE);
    
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .cacheOnDisk(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new FadeInBitmapDisplayer(300))
                .imageScaleType(ImageScaleType.NONE)
                .build();
    
        ImageLoader.getInstance().displayImage(imageUrl, image, options, simpleImageLoadingListener);
    }
    
    SimpleImageLoadingListener simpleImageLoadingListener = new SimpleImageLoadingListener(){
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            spinner.setVisibility(View.VISIBLE);
        }
    
        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            String message = null;
            switch (failReason.getType()) {
                case IO_ERROR:
                    message = "Input/Output error";
                    break;
                case DECODING_ERROR:
                    message = "Image can't be decoded";
                    break;
                case NETWORK_DENIED:
                    message = "Downloads are denied";
                    break;
                case OUT_OF_MEMORY:
                    message = "Out Of Memory error";
                    break;
                case UNKNOWN:
                    message = "Unknown error";
                    break;
            }
            Toast.makeText(view.getContext(), message, Toast.LENGTH_SHORT).show();
    
            spinner.setVisibility(View.GONE);
        }
    
        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            spinner.setVisibility(View.GONE);
        }
    };
    }
    

    我从活动A到活动B(ImageActivity)的意图

       Intent goToImage = new Intent(InfoActivity.this, ImageActivity.class);
            goToImage.putExtra(ImageActivity.IMAGE_URL, cafe.getImageUrl());
            goToImage.putExtra(ImageActivity.TEXT, cafe.getName());
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(InfoActivity.this,
                        imgCompany, "image");
                startActivity(goToImage, options.toBundle());
            } else {
                startActivity(goToImage);
            }
    

    我知道这是因为不同的图像尺寸和scaletypes,on活动A它是centerCrop并且具有固定大小,在活动B上它是maxtrix和match_parent。 如何在转换中调整动画大小? 在我的情况下,在图像移动到它的位置后调整大小......

0 个答案:

没有答案