魔方翻转动画在Android碎片 [英] Cube Flip animation for Fragments on Android

查看:651
本文介绍了魔方翻转动画在Android碎片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个基本的3D立方体和水平或垂直旋转由90degrees的触摸。我想实现类似于什么是显示在下面的图片的东西。

I want to implement a basic 3d cube and rotate it by 90degrees either horizontally or vertically on Touch. What i want to implement is something similar to what is shown in the image below.

我已经做到了这一点使用 ViewPager ViewTransformer 但我不愉快的结果。动画是不是很顺利,我不能翻转,我要拖我的手指在屏幕上的整个widht旋转立方体。 我想只是将其翻转,但我不能够去实现它。

I've achieved this using ViewPager's ViewTransformer But I am not happy with the result. The animation is not very smooth, and i cannot flip it, i have to drag my finger across the entire widht of the screen to rotate the cube. I want to just flip it, but am not able to achieve it.

我用 BTGridPager-的Andr​​oid 实现上述。但是如前所述,它不是很有说服力。

I've used BTGridPager-Android to achieve the above. But as mentioned, its not very convincing.

下面是我的ViewTransformer code:

Here is my ViewTransformer code:

    public abstract class ABaseTransformer implements PageTransformer {
 @Override
 public void transformPage(View page, float position) {
  onPreTransform(page, position);
  onTransform(page, position);
  onPostTransform(page, position);
 }
protected void onPreTransform(View page, float position) {
  final float width = page.getWidth();

  page.setRotationX(0);
  page.setRotationY(0);
  page.setRotation(0);
  page.setScaleX(1);
  page.setScaleY(1);
  page.setPivotX(0);
  page.setPivotY(0);
  page.setTranslationY(0);
  page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

  if (hideOffscreenPages()) {
   page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
  } else {
   page.setAlpha(1f);
  }
 }


public class HorizontalCubeOutTransformer extends ABaseTransformer {

 @Override
 protected void onTransform(View view, float position) {

  final float normalizedposition = Math.abs(1 - Math.abs(position));

  view.setPivotX(position < 0f ? view.getWidth() : 0f);
  view.setPivotY(view.getHeight() * 0.5f);
  view.setRotationY(90f * position);
  view.setAlpha(normalizedposition);
 }

 @Override
 public boolean isPagingEnabled() {
  return true;
 }

}



public class VerticalCubeOutTransformer extends ABaseTransformer {


 @Override
 protected void onTransform(View view, float position) {

  final float normalizedposition = Math.abs(Math.abs(position) - 1);
  view.setAlpha(normalizedposition);
  view.setTranslationX(view.getWidth() * -position);
  view.setTranslationY(position * view.getHeight());

  view.setPivotX(view.getWidth() * 0.5f);
  view.setPivotY(position < 0f ? view.getHeight() : 0f);
  view.setRotationX(90f * -position);

 }

 @Override
 public boolean isPagingEnabled() {
  return false;
 }
}

我想知道的是如何旋转的翻转动作多维数据集。 注:我想实现这一点没有OpenGL或SurfaceView

What I would like to know is how to rotate the cube on the flip gesture. Note: I would like to achieve this without OpenGL or SurfaceView.

更新: 到现在我已经使用fragmenttransactionExtended实现立方体翻转,但现在我得到了一些其他的问题,因为目前的片段只要翻转开始消失

UPDATE: till now i have implemented the cube flip using fragmenttransactionExtended but now i got some other problem, as the current fragment disappears as soon as the flip begins

推荐答案

您可以使用FragmentTransactionExtended

You can use FragmentTransactionExtended

FragmentTransactionExtended

FragmentTransactionExtended

它提供了所有类型的动画frgaments之间

it provides all types of animations between frgaments

这篇关于魔方翻转动画在Android碎片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆