转载自:http://b275518834201204034558.iteye.com/blog/1486820




过程是:
1:准备好布局如下:
2:翻转view动画,翻转动画的监听。
3:翻转后布局的替换,这里用了隐藏
我用了setVisibility(View.INVISIBLE)



layout/mygaller_item_bg_01是正面
layout/mygaller_item_bg_02是反面
布局1:mygaller_item.xml

<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent" android:orientation="vertical"      android:layout_height="wrap_content" android:padding="25dip"      android:id="@+id/container">      <FrameLayout android:layout_width="fill_parent"          android:orientation="vertical" android:layout_height="wrap_content"          android:id="@+id/container_bg">          <include layout="@layout/mygaller_item_bg_01" />          <include layout="@layout/mygaller_item_bg_02" />      </FrameLayout>  </LinearLayout>

View翻转效果:来源:http://mobile.51cto.com/android-265495.htm

import android.graphics.Camera;  import android.graphics.Matrix;  import android.view.animation.Animation;  import android.view.animation.Transformation;    public class Rotate3d extends Animation {      private final float mFromDegrees;      private final float mToDegrees;      private final float mCenterX;      private final float mCenterY;      private final float mDepthZ;      private final boolean mReverse;      private Camera mCamera;        public Rotate3d(float fromDegrees, float toDegrees, float centerX,              float centerY, float depthZ, boolean reverse) {          mFromDegrees = fromDegrees;          mToDegrees = toDegrees;          mCenterX = centerX;          mCenterY = centerY;          mDepthZ = depthZ;          mReverse = reverse;      }        @Override      public void initialize(int width, int height, int parentWidth,              int parentHeight) {          super.initialize(width, height, parentWidth, parentHeight);          mCamera = new Camera();      }        @Override      protected void applyTransformation(float interpolatedTime, Transformation t) {          final float fromDegrees = mFromDegrees;          float degrees = fromDegrees                  + ((mToDegrees - fromDegrees) * interpolatedTime);          final float centerX = mCenterX;          final float centerY = mCenterY;          final Camera camera = mCamera;          final Matrix matrix = t.getMatrix();          camera.save();          if (mReverse) {              camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);          } else {              camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));          }          camera.rotateY(degrees);          camera.getMatrix(matrix);          camera.restore();          matrix.preTranslate(-centerX, -centerY);          matrix.postTranslate(centerX, centerY);      }  }  

过程和动画翻转的控制

public class ViewRotate implements OnClickListener {      private ImageView imageview;      private View bg;      private DisplayNextView displayNextView;      private Context context;      private View convertView;      private LayoutInflater mInflater;      private boolean now_zhengfan;      private View container_bg;        public ViewRotate(Context context, View convertView,              LayoutInflater mInflater) {          this.context = context;          this.convertView = convertView;          this.mInflater = mInflater;          now_zhengfan = true;          AnimationUtils.loadAnimation(context, R.anim.my_alpha_action);          init();      }        public void init() {                      bg = (ViewGroup) convertView.findViewById(R.id.container);          bg.findViewById(R.id.btn_more).setOnClickListener(this);          container_bg = convertView.findViewById(R.id.container_bg);            container_bg          .setBackgroundDrawable(GraphicsBitmapUtils.                  BitmapToDrawable(GraphicsBitmapUtils.getRoundedCornerBitmap(GraphicsBitmapUtils                  .drawableToBitmap(context.getResources()                          .getDrawable(R.drawable.zh)))));      }        private void applyRotation(int position, float start, float end) {          // Find the center of the container          final float centerX = bg.getWidth() / 2.0f;          final float centerY = bg.getHeight() / 2.0f;          final Rotate3d rotation = new Rotate3d(start, end, centerX, centerY,                  310.0f, false);          rotation.setDuration(500);          rotation.setFillAfter(false);          rotation.setInterpolator(new AccelerateInterpolator());          rotation.setAnimationListener(new DisplayNextView(position, true));          bg.startAnimation(rotation);              AlphaAnimation alphaAnim = new AlphaAnimation(0, 1);      }        @Override      public void onClick(View v) {          // TODO Auto-generated method stub          bg.setEnabled(false);          applyRotation(0, 0, 90);      }        private final class DisplayNextView implements Animation.AnimationListener {          private final int mPosition;          private final boolean b;            private DisplayNextView(int position, boolean t) {              mPosition = position;              b = t;          }            public void onAnimationStart(Animation animation) {          }            public void onAnimationEnd(Animation animation) {              if (b) {                  bg.post(new SwapViews(mPosition));                  if (now_zhengfan) {                      bg.findViewById(R.id.backe_bg1).setVisibility(                              View.INVISIBLE);                  } else {                      bg.findViewById(R.id.backe_bg2).setVisibility(                              View.INVISIBLE);                  }              } else {                    bg.setEnabled(true);                  if (now_zhengfan) {                      bg.findViewById(R.id.backe_bg2).setVisibility(View.VISIBLE);                      bg.setOnClickListener(ViewRotate.this);                      bg.setClickable(true);                        AlphaAnimation alphaAnim = new AlphaAnimation(0, 1);                      alphaAnim.setDuration(2000);                      alphaAnim.setStartOffset(500);                      alphaAnim                              .setAnimationListener(new CanClickAnimationListener(                                      bg));                      bg.findViewById(R.id.backe_bg2).startAnimation(alphaAnim);                      now_zhengfan = false;                  } else {                      bg.findViewById(R.id.backe_bg1).setVisibility(View.VISIBLE);                      bg.setOnClickListener(ViewRotate.this);                        now_zhengfan = true;                      bg.setClickable(false);                      View btn = bg.findViewById(R.id.btn_more);                      btn.setOnClickListener(ViewRotate.this);    //                  container_bg  //                          .setBackgroundDrawable(GraphicsBitmapUtils.BitmapToDrawable(GraphicsBitmapUtils.getRoundedCornerBitmap(GraphicsBitmapUtils  //                                  .drawableToBitmap(context.getResources()  //                                          .getDrawable(R.drawable.zh)))));                        AlphaAnimation alphaAnim = new AlphaAnimation(0, 1);                      alphaAnim.setDuration(2000);                      alphaAnim.setStartOffset(500);                      alphaAnim                              .setAnimationListener(new CanClickAnimationListener(                                      bg, btn));                        bg.findViewById(R.id.backe_bg1).startAnimation(alphaAnim);                      // bg.findViewById(R.id.backe_bg1).startAnimation(                      // CopyOfTestRotate.this.animation);                    }              }            }            public void onAnimationRepeat(Animation animation) {            }      }        private final class SwapViews implements Runnable {          private final int mPosition;            public SwapViews(int position) {              mPosition = position;          }            public void run() {              final float centerX = bg.getWidth() / 2.0f;              final float centerY = bg.getHeight() / 2.0f;              Rotate3d rotation;              if (mPosition > -1) {                    rotation = new Rotate3d(90, 180, centerX, centerY, 310.0f,                          false);                  rotation.setAnimationListener(new DisplayNextView(mPosition,                          false));              } else {                  rotation = new Rotate3d(90, 0, centerX, centerY, 310.0f, false);              }              rotation.setDuration(500);              rotation.setFillAfter(false);              rotation.setInterpolator(new DecelerateInterpolator());              bg.startAnimation(rotation);              bg.setEnabled(false);          }      }    }  

更多相关文章

  1. 相对布局解析以及Android(安卓)studio 连接夜神模拟器
  2. 安卓开发_浅谈Android动画(二)
  3. Android(安卓)self_adaption of screen
  4. Android的加载动画AVLoadingIndicatorView
  5. android 调用视图报错The specified child already has a parent
  6. 【Android】使用v7.widget.GridLayout做九宫格。
  7. Android(安卓)相对布局中的 代码中修改属性与布局文件的设置不同
  8. Android学习过程中问题记录
  9. Fragment使用

随机推荐

  1. 如何使用myisamchk和mysqlcheck工具快速
  2. 详解MySQL 8.0.18命令
  3. Linux下彻底删除Mysql 8.0服务的方法
  4. 浅析centos 7 mysql-8.0.19-1.el7.x86_64
  5. mysql8.0.19忘记密码的完美解决方法
  6. CentOS7.5 安装 Mysql8.0.19的教程图文详
  7. MySQL 8.0.19支持输入3次错误密码锁定账
  8. MySQL8.0.19安装教程
  9. workerman写mysql连接池的实例代码
  10. MySQL数据库优化之索引实现原理与用法分