How to Apply Corner Radius to LinearLayout

前端 未结 4 1883
傲寒
傲寒 2020-11-29 16:37

I want to make a layout with a rounded border. How can I apply a radius of a particular size in a LinearLayout?

4条回答
  •  醉酒成梦
    2020-11-29 17:03

    try this, for Programmatically to set a background with radius to LinearLayout or any View.

     private Drawable getDrawableWithRadius() {
    
        GradientDrawable gradientDrawable   =   new GradientDrawable();
        gradientDrawable.setCornerRadii(new float[]{20, 20, 20, 20, 20, 20, 20, 20});
        gradientDrawable.setColor(Color.RED);
        return gradientDrawable;
    }
    
    LinearLayout layout = new LinearLayout(this);
    layout.setBackground(getDrawableWithRadius());
    

提交回复
热议问题