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

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

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

2019-11-09 18:12:12
字體:
來源:轉載
供稿:網友

視差特效

先要設置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); } });
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵州省| 金平| 大安市| 汪清县| 伊吾县| 济宁市| 滨州市| 广州市| 偃师市| 偏关县| 辽阳县| 中西区| 墨竹工卡县| 江山市| 九龙县| 孟津县| 新干县| 满洲里市| 福清市| 承德市| 玉林市| 黄浦区| 布尔津县| 贵港市| 隆尧县| 延津县| 遵义县| 佛山市| 萍乡市| 丹凤县| 松江区| 晋中市| 宁津县| 凤冈县| 麻城市| 桐庐县| 松潘县| 甘孜| 卓资县| 湘西| 内黄县|