android - 尝试旋转布局图像时离开屏幕
问题描述
我正在尝试旋转包含图像的布局。按下时,按钮布局正在旋转,但它会离开屏幕。我试过这样旋转;
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>
如果图像是全屏的,则没有问题。但图像是这样的,出了点问题。
如何解决这个问题呢 ?请帮助我,谢谢
解决方案
设置枢轴
layout.setPivotX(layout.getWidth() / 2);
layout.setPivotY(layout.getHeight() / 2);
推荐阅读
- javascript - JavaScript:处理重定向时的卸载事件
- user-interface - 每次按下带有 Button 组件的 GameObject 时,如何播放声音?
- node.js - 为什么使用护照本地策略加上jwt策略
- reactjs - 如何解决问题 react Switch Autocomplete import from react-router-dom
- npm - npm、grunt 和 webpack 在应用方面有什么区别?
- tensorflow - “尝试使用没有 BLAS 支持的 StreamExecutor 执行 BLAS 操作”错误发生
- angular - 如何将 Themeforest 的 Angular 模板集成到 Jhipster 应用程序中?
- node.js - 如何加载ejs页面并从ajax成功注入数据
- c# - 怎么可能只运行一次代码?
- android - 出现和消失的 Flutter 键盘