序:
安卓布局显示和消失动画加载方式有两种,一种是通过xml布局,另一个是代码实现。xml布局方式:
xml:
在res-anim文件夹下面添加:
alpha_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="10%p" android:toYDelta="0" android:duration="800"/>//从上往下移动显示
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" />//从透明到不透明在1s内
</set>
alpha_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="800"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000" />
</set>
代码调用:
Animation mShowAction = AnimationUtils.loadAnimation(this, R.anim.push_up_in);
Animation mHiddenAction = AnimationUtils.loadAnimation(this, R.anim.push_up_out);
mOne.setVisibility(View.VISIBLE);
mOne.startAnimation(mShowAction);
mOne.setVisibility(View.GONE);
mOne.startAnimation(mHiddenAction);
代码实现方法:
Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -6.0f, Animation.RELATIVE_TO_SELF, 0.0f);
mShowAction.setDuration(1500);
increaseTV.setAnimation(mShowAction);