Android 控件的相对动画实现小说阅读的上下菜单的隐藏与显示

直接上代码:


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就可以播放动画了。


下面上效果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值