【发布时间】:2019-12-08 17:17:15
【问题描述】:
我正在尝试旋转包含图像的布局。按下时,按钮布局正在旋转,但它会离开屏幕。我试过这样旋转;
private void changeRotation(float rotation) {
layout.setRotation(rotation);
layout.setTranslationX(0);
layout.setTranslationY(0);
layout.requestLayout();
isRotated = true;
newRotationValue = rotation;
}
我的布局是这样的;
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/transparent"
tools:context=".activity.CropActivity">
<LinearLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="8dp"
android:orientation="horizontal"
android:weightSum="3">
<info.hoang8f.widget.FButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_margin="8dp"
android:layout_weight="1"
android:drawableStart="@drawable/ic_camera"
android:onClick="cameraBtnClick"
android:padding="16dp"
android:text="Camera"
android:textColor="@color/colorPrimaryDark"
app:cornerRadius="16dp"
app:fButtonColor="@color/colorAccent"
app:shadowColor="@color/colorBlack"
app:shadowEnabled="true"
app:shadowHeight="2dp" />
<info.hoang8f.widget.FButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_margin="8dp"
android:layout_weight="1"
android:drawableStart="@drawable/ic_gallery"
android:onClick="galleryBtnClick"
android:padding="16dp"
android:text="Gallery"
android:textColor="@color/colorPrimaryDark"
app:cornerRadius="16dp"
app:fButtonColor="@color/colorAccent"
app:shadowColor="@color/colorBlack"
app:shadowEnabled="true"
app:shadowHeight="2dp" />
<info.hoang8f.widget.FButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_margin="8dp"
android:layout_weight="1"
android:drawableStart="@drawable/ic_rotate"
android:onClick="rotateBtnClick"
android:padding="16dp"
android:text="Rotate"
android:textColor="@color/colorPrimaryDark"
app:cornerRadius="16dp"
app:fButtonColor="@color/colorAccent"
app:shadowColor="@color/colorBlack"
app:shadowEnabled="true"
app:shadowHeight="2dp" />
</LinearLayout>
</FrameLayout>
如果图像是全屏的,则没有问题。但是图像是这样的,出了点问题。
如何解决这个问题?请帮帮我,谢谢
【问题讨论】:
-
可以发截图吗?
-
已添加请查看
-
@JDevoloper 你能在图片旋转之前发布图片吗?
-
已发布,请查看@VarunRaj
-
在您的情况下,旋转点应该是
height/2和width/2的视图中心。
标签: android image layout rotation