百思不得其解,关于立方体旋转动画(垂直方向)
====================问题描述====================
想做个自定义的view 竖直滑动手势就是翻页。
效果大概是这样的

我用的是属性动画。
用的rotation那个方法让下面的view从-90转到0 上面的view从0转到90
但是 效果跟预期不一样。

求助,有做过的大神来帮帮忙。十分感谢。
下面是我的主要的代码
public class MainActivity extends Activity {
private Button btn;
private ImageView ia, ib;
private int i = -90;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
ia = (ImageView) findViewById(R.id.imageView1);
ib = (ImageView) findViewById(R.id.imageView2);
ia.setPivotX(100);
ia.setPivotY(0);
ib.setPivotX(100);
ib.setPivotY(200);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator oa = ObjectAnimator.ofFloat(ib, "rotationX",
-90, 0);
// ObjectAnimator oa2 = ObjectAnimator.ofFloat(i2, "pivotY", 200,
// 0);
ObjectAnimator oa3 = ObjectAnimator.ofFloat(ia, "rotationX", 0,
90);
// ObjectAnimator oa4 = ObjectAnimator.ofFloat(i1, "pivotY", 200,
// 0);
;
oa.setDuration(10000);
// oa2.setDuration(10000);
oa3.setDuration(10000);
// oa4.setDuration(10000);
oa.setInterpolator(new LinearInterpolator());
// oa2.setInterpolator(new LinearInterpolator());
oa3.setInterpolator(new LinearInterpolator());
// oa4.setInterpolator(new LinearInterpolator());
AnimatorSet as = new AnimatorSet();
as.playTogether(oa, oa3);
as.start();
}
});
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="123" /> <ImageView android:id="@+id/imageView2" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:rotationX="-90" android:scaleType="fitXY" android:src="@drawable/tx" /> <ImageView android:id="@+id/imageView1" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:src="@drawable/tx" /> <!-- <com.example.zdemo10.CubeView android:id="@+id/imageView3" android:layout_width="100dp" android:layout_height="100dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> --> </RelativeLayout>
====================解决方案1====================
没搞过这玩意 说下我的看法
setPivotX()和setPivotY()是设定旋转轴的位置 进行旋转的时候是以这个轴旋转的
从你画的图也可以看出来 两个图片的旋转轴是已经钉死了
但是你的需求上旋转轴是要移动的 是从屏幕顶端到底端的
你需要确定这样做是不是可以的
具体的说 在动画过程中重新设置旋转轴 动画会不会出问题
如果出问题了 有没有其他设置旋转轴的方法
如果还是不行 是不是考虑自己实现这个动画 (实际上只是两个matrix操作而已...)
====================解决方案2====================
用Camera来计算出一个matrix吧。
去我的blog看看这篇文章《Android 3D旋转动画效果》
http://blog.csdn.net/leehong2005/article/details/9126369

浙公网安备 33010602011771号