我有一个3列和无限行的网格视图。我希望:
我曾经想过,我可以为每个场景创建4个xml文件,但我意识到,我需要创建的不仅仅是4个,我还需要再创建一个,以防网格中只有一个条目。如果网格中只有1行,中间项多一行,谁知道.
我只是想知道这个问题是否有一个更优雅的解决办法。
发布于 2017-02-27 01:29:35
下面的代码可能对您有帮助,
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。
https://stackoverflow.com/questions/42475178
复制相似问题