一实现imageView的点击事件实现图片的放大与缩小:
((ShopDetailsViewHolder) holder).img_list.setOnClickListener(new View.OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onClick(View v) { Intent intent = new Intent(v.getContext(), OtherActivity.class); Bundle bundle = new Bundle(); bundle.putSerializable("imgUrl", list.get(position)); intent.putExtras(bundle); v.getContext().startActivity(intent); //图片放大操作 ActivityOptions.makeSceneTransitionAnimation((Activity) v.getContext(), v, "sharedView").toBundle(); } });
二 创建放大图片的Activity的类
布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--注意这里的sharedView--> <ImageView android:id="@+id/imageView2" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@mipmap/ic_launcher" android:transitionName="sharedView" /> </LinearLayout>
Activity视图:
ImageView imageView2 = findViewById(R.id.imageView2); Intent intent = getIntent(); String ingUlr = intent.getStringExtra("imgUrl"); Picasso.with(this).load(ingUlr).into(imageView2); findViewById(R.id.imageView2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 注意这里不使用finish ActivityCompat.finishAfterTransition(OtherActivity.this); } });