Java 如何设置水平仪栏的动画?
我对Java和android studio还相当陌生。我想动画我的酒吧,我用随机值创建。我用android studio创建了customView,并绘制了一个画布矩形。下一步是输入一些随机值并设置条的动画。我用JavaScript(Java 如何设置水平仪栏的动画?,java,android,canvas,android-custom-view,Java,Android,Canvas,Android Custom View,我对Java和android studio还相当陌生。我想动画我的酒吧,我用随机值创建。我用android studio创建了customView,并绘制了一个画布矩形。下一步是输入一些随机值并设置条的动画。我用JavaScript(Math.random)实现了这一壮举 public class CustomView extends View { private Rect rect; private Paint paint; int radius;
Math.random
)实现了这一壮举
public class CustomView extends View {
private Rect rect;
private Paint paint;
int radius;
public CustomView(Context context){
super(context);
init(null);
}
public CustomView(Context context, AttributeSet attrs){
super(context, attrs);
init(attrs);
}
public CustomView(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
init(attrs);
}
public CustomView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
super(context, attrs, defStyleAttr, defStyleRes);
init(attrs);
}
private void init(@Nullable AttributeSet set){
rect = new Rect();
// the flag is more pixelated
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
postInvalidate();
}
//drawing a canvas
@Override
protected void onDraw(Canvas canvas){
int viewWidth = getWidth();
int viewHeight = getHeight();
int leftTopX = viewWidth - 750;
int leftTopY = viewHeight - 750;
int rightBotX = viewWidth + 150;
int rightBotY = viewHeight + 150;
paint.setColor(Color.MAGENTA);
canvas.drawRect(leftTopX,leftTopY, rightBotX,rightBotY,paint);
paint.setColor(Color.GREEN);
}
}
到目前为止,我已经做到了这一点。但我如何用Java为酒吧制作动画呢
我已经实现了progressbar dude。谢谢您提供的信息!!快乐编码。干杯
Try this -
I used it with seekbar. You can use it for your view. As per your case. You should Progressbar or Seekbar.
seekbar = ((CustomSeekbar) findViewById(R.id.customSeekBar));
seekbar.setMax(2600);
final ObjectAnimator animation = ObjectAnimator.ofInt(seekbar, "progress", 0, 800;
animation.setDuration(1500);
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
seekbar.clearAnimation();
Here 0 is the starting value and 800 is the max value. Please change is as per your requirement.