使用动画应用在控件的显示和隐藏上,实例代码是实现的是显示时逐渐从透明到不透明过渡,同时移动一小段距离!
程序中已打包多种动画效果,可组合使用!
滑入:
<set xmlns:android="/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" /></set>
滑出:
<set xmlns:android="/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>
调用:
public void onClick(View view) {if (view.getId() == R.id.main_text_one) {mOne.setVisibility(View.GONE);mOne.startAnimation(mHiddenAction);mTwo.setVisibility(View.VISIBLE);mTwo.startAnimation(mShowAction);} else {mTwo.setVisibility(View.GONE);mTwo.startAnimation(mHiddenAction);mOne.setVisibility(View.VISIBLE);mOne.startAnimation(mShowAction);}}private void initAnimations_One(){mShowAction = AnimationUtils.loadAnimation(this, R.anim.push_up_in);mHiddenAction = AnimationUtils.loadAnimation(this, R.anim.push_up_out);}private void initAnimations_Two(){mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);mShowAction.setDuration(500);mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,-1.0f);mHiddenAction.setDuration(500);}
转载请注明出处!
本例资源地址:/detail/qiujuer/6934243
如果觉得《[Android] View控件显示隐藏动画效果》对你有帮助,请点赞、收藏,并留下你的观点哦!