Android:使用两种背景颜色制作圆形布局
我想制作一个圆形形状并将其应用为布局上的背景。我已经控制住了,但我想让背景像进度条一样。
这就是我希望它看起来像这样的图像:
我希望能够控制 bg 的位置改变所以我想它应该在代码中完成。 它必须以某种方式完成,这样我就可以在它上面放置文本,
此时我有用于创建圆角形状的代码:
int w = this.getWidth() - this.getPaddingLeft() - this.getPaddingRight();
int 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);
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:
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 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论