国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

自定義view實戰筆記--視差特效

2019-11-09 17:10:41
字體:
來源:轉載
供稿:網友

視差特效

先要設置imageview的scaleType屬性為centerCrop

動態的改變一個控件的寬高可以在屬性動畫中不斷修改布局參數的值,然后調用該控件的iv_header.requestLayout();方法

// 把當前的頭布局的高度currentHeight恢復到初始高度orignalHeight final int currentHeight = iv_header.getHeight(); // 300 -> 160 ValueAnimator animator = ValueAnimator.ofInt(currentHeight, orignalHeight); // 動畫更新的監聽 animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // 0.0 -> 1.0 // 獲取動畫執行過程中的分度值 float fraction = animation.getAnimatedFraction();// Integer evaluate = evaluate(fraction, currentHeight, orignalHeight); // 獲取中間的值 Integer animatedValue = (Integer) animation.getAnimatedValue(); System.out.注意點:可以用以下代碼在activity的onCreate()方法中獲取控件的寬高,但要注意,在在獲取完畢之后要移除監聽,否則會被反復調用賦值

ivHeader.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // 圖片的原始高度 drawableHeight = ivHeader.getDrawable().getIntrinsicHeight(); //Imageview的初始高度,用來做動畫 originalHeight = ivHeader.getHeight(); ivHeader.getViewTreeObserver().removeGlobalOnLayoutListener(this); } });
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河曲县| 永寿县| 栖霞市| 泸州市| 扎鲁特旗| 惠州市| 福鼎市| 平昌县| 虹口区| 托里县| 邵阳市| 怀宁县| 延津县| 沙湾县| 和政县| 固原市| 高阳县| 金溪县| 建平县| 邢台市| 科技| 莎车县| 仲巴县| 肥城市| 阿巴嘎旗| 新乡市| 高碑店市| 涟源市| 张家川| 高要市| 简阳市| 洪湖市| 余干县| 衡南县| 诸暨市| 三门县| 绩溪县| 泾阳县| 天门市| 铁岭县| 紫阳县|