今天准备比赛的时候 遇到了这个问题。
查了些资料总结了下。
主要是通过
android: theme 标签来实现
android: theme="@style/xxx"
那么就需要自己写style风格文件
如下
<style name="ThemeActivity" mce_bogus="1"> <item name="android:windowAnimationStyle">@style/AnimationActivity</item> <item name="android:windowNoTitle">true</item> </style> <style name="AnimationActivity" mce_bogus="1" parent="@android:style/Animation.Activity"> //需要继承自android:style/Animation.Activity <item name="android:activityOpenEnterAnimation">@anim/anim_enter</item> <item name="android:activityOpenExitAnimation">@anim/anim_exit</item> <item name="android:activityCloseEnterAnimation">@anim/back_enter</item> <item name="android:activityCloseExitAnimation">@anim/back_exit</item> </style> //这里之所以写成2style个是为了解耦
然后自己写下anim/anim_enter anim/anim_exit 以及amin_back_enter amin_back_enter
===============我是分割线===================
今天同样遇到一个问题
就是用xml写amin时候
我把scale 标签的 pivotX 与 pivotY
的含义理解错了 实际含义应该是相对物件的X,Y标志位。(0%~100%)
而
fromXScale[float] fromYScale[float] | 为动画起始时,X、Y坐标上相对 pivotX 的伸缩尺寸 |
0.0表示收缩到没有
物件伸展过程中不会移出物件 | |
toXScale [float] toYScale[float] | 为动画结束时,X、Y坐标上相对 pivotY的伸缩尺寸(参数含义同上) |
==============我是分界线====================
关于android anim动画 的越界问题
在动画使用过程中
scale 是不能越界的 只能显示在View本身的范围内
translate 可以越界的 但只能在该view的父view的范围内显示超出则不显示 (它标记的x,y是相对于所在view的左上标志点位)
rotate 可以越界的 但只能在该view的父view的范围内显示超出则不显示
==============我是分割线====================
animation.setFillAfter(true)方法可以实现动画结束后 图片停止在动画结束的位置[view的实际位置不改变]
从而可以通过动画实现新浪微博消息页上导航的选择切换效果
/**
* 初始化动画
*/
private void InitImageView() {
cursor = (ImageView) findViewById(R.id.cursor);
bmpW = BitmapFactory.decodeResource(getResources(), R.drawable.a)
.getWidth();// 获取图片宽度
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenW = dm.widthPixels;// 获取分辨率宽度
offset = (screenW / 3 - bmpW) / 2;// 计算偏移量
Matrix matrix = new Matrix();
matrix.postTranslate(offset, 0);
cursor.setImageMatrix(matrix);// 设置动画初始位置 只改变显示位置 不影响初始位置(既不影响top|left坐标点)
}
int one = offset * 2 + bmpW;
// 页卡1 -> 页卡2 偏移量
int two = one * 2;
// 页卡1 -> 页卡3 偏移量
@Override public void onPageSelected(int arg0) { Animation animation = null; switch (arg0) { case 0: if (currIndex == 1) { animation = new TranslateAnimation(one, 0, 0, 0); } else if (currIndex == 2) { animation = new TranslateAnimation(two, 0, 0, 0); } break; case 1: if (currIndex == 0) { animation = new TranslateAnimation(offset, one, 0, 0); } else if (currIndex == 2) { animation = new TranslateAnimation(two, one, 0, 0); } break; case 2: if (currIndex == 0) { animation = new TranslateAnimation(offset, two, 0, 0); } else if (currIndex == 1) { animation = new TranslateAnimation(one, two, 0, 0); } break; } currIndex = arg0; animation.setFillAfter(true);
// True:图片停在动画结束位置
animation.setDuration(300); cursor.startAnimation(animation); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { }