DemoImageView
DemoImageView
<TextView
android:id="@+id/textView"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Center" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="centerCrop" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="centerInside" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="fitCenter" />
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="fitEnd" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="fitStart" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="fitXY" />
</LinearLayout>
<ImageView
android:scaleType="center"
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:srcCompat="@drawable/vitdonnald" />
</LinearLayout>
MainActivity.java
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.button3:
imageView2.setScaleType(ImageView.ScaleType.CENTER);
textView.setText("Center Style");
break;
case R.id.button4:
imageView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
textView.setText("Center Crop Style");
break;
case R.id.button5:
imageView2.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
textView.setText("Center Inside Style");
break;
case R.id.button6:
imageView2.setScaleType(ImageView.ScaleType.FIT_CENTER);
textView.setText("Center Center Style");
break;
case R.id.button7:
imageView2.setScaleType(ImageView.ScaleType.FIT_END);
textView.setText("Center FitEnd Style");
break;
case R.id.button8:
imageView2.setScaleType(ImageView.ScaleType.FIT_START);
textView.setText("Center FitStart Style");
break;
case R.id.button9:
imageView2.setScaleType(ImageView.ScaleType.FIT_XY);
textView.setText("Center FitXY Style");
break;
}
}
}