我想在图像视图上执行动画以更改图像视图的宽度,如下所示

时间:2012-08-30 11:13:59

标签: android android-layout

我想在imageview上做动画,如下所示 First image

Second Image

third Image

需要设置这样的动画。

1 个答案:

答案 0 :(得分:0)

找到解决方案 ScaleAnimation解决了这个问题

int maxValue = 6085;
final float scale = this.getResources().getDisplayMetrics().density;
linearLayout1 =(LinearLayout) findViewById(R.id.iv1);linearLayout2 =(LinearLayout) findViewById(R.id.iv2);

linearLayout1.setLayoutParams(new LinearLayout.LayoutParams(calculatePercentage(maxValue,3853),(int) (20 * scale + 0.5f)));
        linearLayout2.setLayoutParams(new LinearLayout.LayoutParams(calculatePercentage(maxValue,3026), (int) (20 * scale + 0.5f)));

ScaleAnimation anim1 = new ScaleAnimation(0.0f, 10.0f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,1.0f, Animation.RELATIVE_TO_SELF, 0.5f);
        ScaleAnimation anim2 = new ScaleAnimation(0.0f, 10.0f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
            anim1.setDuration(7000);
            anim2.setDuration(7000);
           linearLayout1.startAnimation(anim1);
           linearLayout2.startAnimation(anim2);

和计算百分比的代码

public int calculatePercentage(int maxValue,int value)
    {
        Log.v(TAG, "maxValue  :  "+maxValue);
        Log.v(TAG, "Value  :  "+value);
        float division =(float)(value)/(float)maxValue;
        int percenatgeValue =(int) (division*100);
        Log.v(TAG, "percenatgeValue  :  "+percenatgeValue);
        return percenatgeValue;
    }