如何将圆形动画的固定大小设置为android

时间:2015-09-20 14:55:31

标签: android

固定大小圈子aniamtion问题

你好,我有这个班:

 public circle (Context context, AttributeSet attrs)  {


    super(context, attrs);

    final int strokeWidth = 30;

    paint = new Paint();

    paint.setAntiAlias(true);

    paint.setStyle(Paint.Style.STROKE);

    paint.setStrokeWidth(strokeWidth);

    //Circle color

    paint.setColor(Color.YELLOW);


    //size 200x200 example

    rect = new RectF(strokeWidth, strokeWidth, 350 + strokeWidth, 350 +

    strokeWidth);


    //Initial Angle (optional, it can be zero)

    angle = 0;
}

@Override

protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);

    canvas.drawArc(rect, START_ANGLE_POINT, angle, false, paint);



}

public float getAngle() {

    return angle;
}

public void setAngle(float angle) {

    this.angle = angle;

}



}

这个类负责动画绘制圈

动画类是:

public class CircleAngleAnimation extends Animation {

private circle circle;

private float oldAngle;

private float newAngle;

public CircleAngleAnimation(circle circle, int newAngle) {

this.oldAngle = circle.getAngle();

this.newAngle = newAngle;

this.circle = circle;
}

@Override

protected void applyTransformation(float interpolatedTime, Transformation

transformation) {  

float angle = oldAngle + ((newAngle - oldAngle) * interpolatedTime);

circle.setAngle(angle);

circle.requestLayout();

}


}

我将mainactivity.xml中的xml值附加到圆圈类,如下所示:

       <com.mynetwork.zaidkhaled.speech.circle
        android:id="@+id/circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:gravity="center_horizontal"
        />

在mainactivity中我设置了animation = new CircleAngleAnimation(circle,360); animation.setDuration(1000);然后我通过circle.startanimation(动画)调用开始动画;

现在我的问题是当这个圆圈在活动中被绘制时,如果屏幕分辨率很高,它将被完美地绘制,完美的大小,如果屏幕分辨率低,它将绘制得非常大,如何设置这个cricle在每个移动设备上绘制相同的大小? 谢谢你的帮助:)

0 个答案:

没有答案
相关问题