过程是:
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);
}
}
}
分享到:
相关推荐
NULL 博文链接:https://hz-chenwenbiao-91.iteye.com/blog/1991264
Android控件大全以及布局控件的使用方式,讲解非常详细。
StatusView:简单的 Android 页面多状态布局切换控件
android 常用控件如:ProgressBar、ActionBar、Switch、ListView 、PopupWindow....等的用法,各种Style的写法以及自定义常用控件 android 五大布局的汇总及用法
Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局Qt动态控件生成并布局...
Android控件,囊括了所有Android控件、用法以及示例
Android点击翻转控件源码
LinearLayout 线性布局 控制组件 横向 或者 纵向 排列 ...GridLayout 网格布局 设置行列来装填控件 AbsoluteLayout 绝对布局 组件位置通过x, y坐标来控制, 布局容器不再管理组件位置, 大小, 这些都可以自定义;
快速理解Android常用控件,线性布局设计及控件参数的设置,计算器,九宫格实现基础
Android 自定义自动换行布局控件
Android基础系列之布局和控件课程对应的代码
Android控件大全以及各布局空间的使用方式
Android 实现控件流式布局, 博客地址:https://blog.csdn.net/dreams_deng/article/details/105489276
Android 中常用的控件介绍及其相应的使用,内含实例代码
Android控件及布局的使用,帮助使用各种控件,多实验掌握
1、基本界面组件 2、布局管理器 3、高级界面组件 4、对话框 5、消息提示 6、菜单