For example:
Create ImageActivity :
public class ImageActivity extends AppCompatActivity { private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image); mImageView = (ImageView) findViewById(R.id.my_image_view); Bundle extras = getIntent().getExtras(); if (extras != null) { int imageId = extras.getInt("image_id"); mImageView.setImageResource(imageId); } } }
Her layout activity_image.xml :
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/my_image_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter"/> </RelativeLayout>
If you need to display a picture, launch ImageActivity :
Intent intent = new Intent(getApplicationContext(), ImageActivity.class); intent.putExtra("image_id", R.drawable.my_image); startActivity(intent);