我試圖在點擊imageView
時使圖像顯示全屏。縮小時ImageView保持居中
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
if (isImageFitToScreen) {
isImageFitToScreen = false;
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER);
} else {
isImageFitToScreen = true;
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
});
XML
<ImageView
android:layout_gravity="center"
android:layout_width="214dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@mipmap/no_image"
android:id="@+id/imageView"
android:layout_weight="0.19" />
的imageView
之前被點擊,imageView
爲中心。當它點擊後恢復到正常尺寸時,imageView
的尺寸變小並移動到左側。如何讓大小保持與正常相同(放大之前)並將imageView修正爲中心?