0

我想在imageview上做动画如下 第一张图片

第二张图片

第三张图片

需要动画才能喜欢这样。

4

1 回答 1

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;
    }
于 2012-10-10T07:50:36.763 回答