Android 控件的相对动画实现小说阅读的上下菜单的隐藏与显示
2017-03-12 22:22
429 查看
直接上代码:
1.这个是相对于自身往上平移自身高度的动画
2.这个是相对于自身往下平移自身高度的动画
其实就是对于
不过在动画的执行的地方有不同,不是通过Start()方法执行动画,而是通过设置View 的Visibility来控制动画的播放。
比如这里有一个需要隐藏的View 变量名为topLayout,
那么这里实现动画的方式就为
下面上效果:
1.这个是相对于自身往上平移自身高度的动画
TranslateAnimation translateAnimation = 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);
2.这个是相对于自身往下平移自身高度的动画
TranslateAnimation translateAnimation1 = 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);
其实就是对于
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)这个方法的调用。
不过在动画的执行的地方有不同,不是通过Start()方法执行动画,而是通过设置View 的Visibility来控制动画的播放。
比如这里有一个需要隐藏的View 变量名为topLayout,
那么这里实现动画的方式就为
toplayout.setAnimation(translateAnimation); toplayout.setVisibility(View.INVISIBLE);这里就可以实现动画的播放,这里设置的是INVISIBLE,是因为我们的控件本来是可见的(VISIBLE),所以动画的控制是通过View的可见性来控制的,也就是说,这里也可以设置为View.GONE,也是可以触发动画。当处于INVISIBLE或者GONE的时候,设置为VISIBLE就可以播放动画了。
下面上效果:
相关文章推荐
- Android 控件的显示隐藏上下左右移动动画
- Android 控件的显示隐藏上下左右移动动画
- Android 控件的显示隐藏上下左右移动动画
- Android 控件的显示隐藏上下左右移动动画
- Android 控件的显示隐藏上下左右移动动画
- Android上实现各种风格的隐藏菜单,比如左右滑动菜单、上下滑动显示隐藏菜单
- android实现点击TextView显示隐藏控件
- android控件显示与隐藏的时候的动画效果
- Android自定义控件View(实现控件的动画效果,自定义类画简略时钟,TextView中文字逐一显示,动态设置progress的圆环/扇形ProgressBar等)
- Android实战简易教程-第五十一枪(ListView实现子控件的动态显示和隐藏、checkbox全选和反选)
- android实现双日期选择控件(可隐藏日,只显示年月)
- Android 动画1--View控件的显示和隐藏效果
- Android实现View隐藏显示渐变动画
- Android播放器菜单的显示隐藏动画效果
- android 下拉筛选菜单 view的显示和隐藏动画
- [Android] View控件显示隐藏动画效果
- Android ViewPager内容部分随手势上下滑动隐藏与显示Indicator效果的实现
- Android控件显示/隐藏时添加动画:ViewSwitcher
- android---控件隐藏与显示动画
- Android ViewPager内容部分随手势上下滑动隐藏与显示Indicator效果的实现