[英]How to create horizontal indeterminate progress drawable with round corners for progressbar in android?
[英]Android Drawable Round Corners Dyanamically
我有3列和无限行的网格视图。 我希望是:
我以为我可以为每种情况创建4个xml文件,但是我意识到我不仅需要创建4个文件,还需要再创建一个,以防网格中只有1个项目。 如果网格中只有1行,则再增加2个,中间项目再增加2行,谁知道...
我只是想知道是否有一个更优雅的解决方案。
以下代码可以为您提供帮助,
GradientDrawable drawable;
makeBackground(drawable, 5, R.color.black, 2, R.color.white);
private void makeBackground(GradientDrawable drawable, int radius, int backgroundColorResource, int borderWidth, int borderColorResource){
drawable.setColor(getColor(getContext(), backgroundColorResource));
drawable.setStroke(dpToPx(borderWidth), getColor(getContext(), borderColorResource));
drawable.setCornerRadius(dpToPx(radius));
}
public static int dpToPx(int dp) {
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
public static int getColor(Context context, int res){
return ContextCompat.getColor(context, res);
}
对于不同角落中的不同值,必须使用setCornerRadii而不是setCornerRadius。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.