3D旋转 - 透视

时间:2014-10-22 16:49:05

标签: android animation 3d rotation perspective

public class MainActivity extends Activity {

LinearLayout rotator;

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    rotator = (LinearLayout) findViewById(R.id.rotator);

    ObjectAnimator rotation = ObjectAnimator.ofFloat(rotator, "rotationY", 0, 360);
    rotation.setDuration(3000);
    rotation.start();

}
}

我有上面的代码,它围绕Y轴旋转View。问题是,透视图似乎太“强烈” - 前景中的视图边缘变得太大而背景中的边缘变得太小。是否有可能“降低”透视因素?

1 个答案:

答案 0 :(得分:8)

int distance = 1900;
float scale = getResources().getDisplayMetrics().density;
rotator.setCameraDistance(distance * scale);

所以这是所有屏幕密度的解决方案。