【发布时间】:2021-01-19 07:50:12
【问题描述】:
我正在使用 Glide 显示图像,我想将它们旋转到不同的角度,
这是我的 xml 代码:
<FrameLayout
android:id="@+id/rootImage"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:layout_gravity="center" />
</FrameLayout>
这里是java代码:
public void rotateImage(float rot) {
if (rot == 90 || rot == 270) {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
int offset = (width - height) / 2;
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(height, width);
ImageLayout.setLayoutParams(lp);
ImageLayout.setRotation(rot);
ImageLayout.setTranslationX(offset);
ImageLayout.setTranslationY(-offset);
} else {
ImageLayout.setRotation(rot);
}
}
当它在 90 时显示这个
【问题讨论】:
标签: android imageview android-glide android-framelayout image-rotation