Android 如何制作10个ImageView';有10个不同的边界角半径,只有1个GradientDrawable xml资源

Android 如何制作10个ImageView';有10个不同的边界角半径,只有1个GradientDrawable xml资源,android,android-layout,android-drawable,xml-drawable,Android,Android Layout,Android Drawable,Xml Drawable,在Android应用程序中, 如何使用1个GradientDrawable xml资源(而不是10个不同的GradientDrawable xml资源)为每个ImageView创建10个具有10个不同边界角半径的ImageView 似乎我应该为每个ImageView使用不同值的setCornerRadius,但问题是如果我为ImageView2设置CornerRadius,那么ImageView1的CornerRadius也会受到影响,如果我为ImageView3设置CornerRadius,然

在Android应用程序中,
如何使用1个GradientDrawable xml资源(而不是10个不同的GradientDrawable xml资源)为每个ImageView创建10个具有10个不同边界角半径的ImageView


似乎我应该为每个ImageView使用不同值的setCornerRadius,但问题是如果我为ImageView2设置CornerRadius,那么ImageView1的CornerRadius也会受到影响,如果我为ImageView3设置CornerRadius,然后ImageView2和ImageView1的CornerRadius也会受到影响,依此类推

您只需从如下java代码创建可绘制的渐变即可-

GradientDrawable drawable = new GradientDrawable();
drawable.setStroke(width, Color.RED);
drawable.setCornerRadius(8);
并将drawable设置为imageview,如下所示

        imageView.setBackgroundDrawable(drawable);

您必须为每个图像视图设置角半径。所以您的意思是,除了利用10个GradientDrawable xml资源之外,别无选择?这是一个奇怪的原因。setStroke没有这样的问题,只要有一个GradientDrawable xml资源,我就可以为ImageView的类
。setStroke()
,您也可以设置
。setCornerRadius()
,但您必须为所有图像视图设置,而不仅仅是单个图像视图。是的,我设置了(Stroke和CornerRadius)对于所有图像视图,不仅是单个图像视图,笔划没有问题,而且CornerRadius也有我提到的问题抱歉,回答与问题无关!