[英]Changing radius of a layout using seekBar in Android
I need to change radius of all four corners of a layout using SeekBar.我需要使用 SeekBar 更改布局的所有四个角的半径。 How can I do that?我怎样才能做到这一点?
I know I can create a layout with round corners using XML, but I need to do it at runtime using SeekBar.我知道我可以使用 XML 创建带圆角的布局,但我需要在运行时使用 SeekBar 来完成。
GradientDrawable shapeDrawable = new GradientDrawable();
shapeDrawable.setShape(GradientDrawable.RECTANGLE);
shapeDrawable.setCornerRadius(100f);
shapeDrawable.setColor(Color.BLACK);
shapeDrawable.setBounds(0,0,600,600);
svMain.setBackgroundDrawable(shapeDrawable);
You can set radius for Drawables but for layouts or Views directly.您可以为 Drawable 设置半径,但可以直接为布局或视图设置半径。 The only exception (for I know) is CardViews, which have radius as an attribute.唯一的例外(据我所知)是 CardViews,它具有半径作为属性。
If it is a CardView, you can easily change its radius dynamically.如果是 CardView,您可以轻松地动态更改其半径。
wrap your layout inside a cardview and change its radius
using将您的布局包裹在cardview 中并使用更改其radius
app:cardCornerRadius="10dp"
simple trick....简单的技巧....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.