![](/img/trans.png)
[英]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.