开发者

Android: make rounded layout with two background colors

开发者 https://www.devze.com 2023-04-10 15:35 出处:网络
I wanted to make a rounded shape and apply it as a background on a layout. This i have under control, but i wanted to make the background like a progressbar.

I wanted to make a rounded shape and apply it as a background on a layout. This i have under control, but i wanted to make the background like a progressbar.

that is i want it to look something like this image:

Android: make rounded layout with two background colors

I want to be able to control where the bg change so i guess it should be done in code. It must be done in a way so i can place text over it

at the moment i have this code for creating a rounded corner shape:

  int w = this.getWidth() - this.getPaddingLeft() - this.getPaddingRight();
  int 开发者_StackOverflow中文版h = this.getHeight() - this.getPaddingTop() - this.getPaddingBottom();
  int progressWidth = Math.round((w * percent) / 100);

  ShapeDrawable shapeDrawable = new ShapeDrawable();
  float[] outerR = new float[]{5, 5, 5, 5, 5, 5, 5, 5};
  RectF inset = new RectF(0, 0, 0, 0);
  float[] innerR = new float[]{0, 0, 0, 0, 0, 0, 0, 0};
  RoundRectShape roundRectShape = new RoundRectShape(outerR, inset, innerR);
  shapeDrawable.setShape(roundRectShape);
  shapeDrawable.getPaint().setColor(progressColor);
  shapeDrawable.setBounds(0,0,w,h);
0

精彩评论

暂无评论...
验证码 换一张
取 消