如何使用10个不同的边角半径制作10个ImageView,只有1个GradientDrawable xml资源

问题描述 投票:1回答:1

在Android应用程序中, 如何使用1个GradientDrawable xml资源(不是10个不同的GradientDrawable xml资源)为每个ImageView制作10个不同边角半径的10个ImageView

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

android android-layout android-drawable xml-drawable
1个回答
1
投票

你可以简单地从java代码创建渐变drawable,如下所示 -

GradientDrawable drawable = new GradientDrawable();
drawable.setStroke(width, Color.RED);
drawable.setCornerRadius(8);

并将drawable设置为imageview,如下所示

        imageView.setBackgroundDrawable(drawable);
© www.soinside.com 2019 - 2024. All rights reserved.