我使用 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 时显示这个
答案 0 :(得分:0)
使用这个
android:scaleType="fitX"
它将水平扩展您的图像,去除多余的填充
你也可以使用
android:scaleType="fitXY"
它将在垂直和水平方向上扩展