How to make layout with rounded corners..?

后端 未结 18 3265
独厮守ぢ
独厮守ぢ 2020-11-22 09:37

How can I make a layout with rounded corners? I want to apply rounded corners to my LinearLayout.

18条回答
  •  佛祖请我去吃肉
    2020-11-22 09:58

    Function for set corner radius programmatically

    static void setCornerRadius(GradientDrawable drawable, float topLeft,
            float topRight, float bottomRight, float bottomLeft) {
        drawable.setCornerRadii(new float[] { topLeft, topLeft, topRight, topRight,
                bottomRight, bottomRight, bottomLeft, bottomLeft });
    }
    
    static void setCornerRadius(GradientDrawable drawable, float radius) {
        drawable.setCornerRadius(radius);
    }
    

    Using

    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setColor(Color.GREEN);
    setCornerRadius(gradientDrawable, 20f);
    //or setCornerRadius(gradientDrawable, 20f, 40f, 60f, 80f); 
    
    view.setBackground(gradientDrawable);
    

提交回复
热议问题