我正在为android(api> 14)实现3d卡翻转动画,并且有大屏幕平板电脑(> 2048 dpi)的问题.在问题调查期间,我来到以下基本块:
尝试使用矩阵和相机的旋转Y转换视图(简单的ImageView)一些角度,它适用于角度<60和角度> 120(转换和显示)但是当角度在60和60之间时图像消失(只是不显示) 120.这是我使用的代码:
private void applyTransform(float degree)
{
float [] values = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
float centerX = image1.getMeasuredWidth() / 2.0f;
float centerY = image1.getMeasuredHeight() / 2.0f;
Matrix m = new Matrix();
m.setValues(values);
Camera camera = new Camera();
camera.save();
camera.rotateY(degree);
camera.getMatrix(m);
camera.restore();
m.preTranslate(-centerX, -centerY); // 1 draws fine without these 2 lines
m.postTranslate(centerX, centerY); // 2
image1.setImageMatrix(m);
}
Run Code Online (Sandbox Code Playgroud)
这是我的布局XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud)