android 透明度变化,安卓获取屏幕的宽高并设置平移动画和透明度变化
在做X6影院的時候遇到了一個問題,需要在引導頁做特效,做一個平移的動畫,在平移的同時,做透明度變化。
//平移動畫。需要獲取到屏幕的寬高比,獲取代碼如下private?WindowManager?windowManager;
private?int?width;
private?int?height;
windowManager=?this.getWindowManager();
width?=?windowManager.getDefaultDisplay().getWidth();//好的寬度
height?=?windowManager.getDefaultDisplay().getHeight();//獲得高度
要讓兩個動畫同時執行。可以用動畫集合的方式,把兩個動畫都放到一個集合中。代碼如下:
private?ImageView?imageView;
public?final?long?ANIMATION_TIME?=?2500;
imageView?=?(ImageView)findViewById(R.id.logo);
//1.透明度變化特效
AlphaAnimation?animation?=?new?AlphaAnimation(0,1);
animation.setDuration(ANIMATION_TIME);
animation.setFillAfter(true);
//2.移動動畫
TranslateAnimation?translateAnimation?=?new?TranslateAnimation(0,0,0,-100);//float?fromXDelta?動畫開始的點離當前View?X坐標上的差值???float?toXDelta?動畫結束的點離當前View?X坐標上的差值???float?fromYDelta?動畫開始的點離當前View?Y坐標上的差值???float?toYDelta?動畫開始的點離當前View?Y坐標上的差值
translateAnimation.setDuration(ANIMATION_TIME);
translateAnimation.setFillAfter(true);
//設置動畫集合
AnimationSet?set?=?new?AnimationSet(false);
set.addAnimation(animation);
set.addAnimation(translateAnimation);
imageView.startAnimation(set);
總結
以上是生活随笔為你收集整理的android 透明度变化,安卓获取屏幕的宽高并设置平移动画和透明度变化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux如何get请求urlencod
- 下一篇: android时间轴左右交叉布局,快速简