我想在imageview上做动画,如下所示
需要设置这样的动画。
答案 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;
}