2016-03-09 44 views
0

我有一個線性佈局,我想動畫來調整大小,當我點擊它。調整大小後,您應該可以看到按鈕和文字。我試着用這個動畫:動畫調整大小的視圖,而不調整視圖內的大小按鈕

container.animate().scaleX(scale); 
container.animate().scaleY(scale); 

而且我想這:

container.startAnimation(anim); 

其中阿尼姆是(爲了使視圖更大):

<scale 
    android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
    android:fromXScale="1.0" 
    android:toXScale="10.0" 
    android:fromYScale="1.0" 
    android:toYScale="10.0" 
    android:pivotX="0%" 
    android:pivotY="0%" 
    android:fillAfter="false" 
    android:duration="700" /> 

但問題是,每次我調整LinearLayout的大小時,內部的子項也會被調整大小。這應該與AndroidSDK 16及更高版本兼容。如何實現this沒有調整裏面的孩子?

感謝

回答

0

你好,你可以覆蓋孩子的onMeasure()方法,並使其尺寸例如常量。

0
float scale = 1.2f; 
ValueAnimator animator = ValueAnimator.ofInt(0,100); 
animator.setTarget(container); 
animator.setDuration(1000).start(); 
animator.addUpdateListener(new AnimatorUpdateListener() 
{ 
    @Override 
    public void onAnimationUpdate(ValueAnimator animation) 
    { 
     LayoutParams layoutparams = container.getLayoutParams(); 
     layoutparams.height = (int)(layoutparams.height* animation.getAnimatedValue() *(scale -1f)); 
     layoutparams.width= (int)(layoutparams.width* animation.getAnimatedValue() *(scale -1f)); 
     container.setLayoutParams(layoutparams); 
    } 
});