Biswajit Das
Biswajit Das

Reputation: 644

Round corner shape RelativeLayout

I am working on layout on Android project. Where the layout parameters are coming programmically. My current layout is coming -

enter image description here

Code-

mRedBackground=initBackground(getResources().getColor(R.color.transparent_red_80), this.mWidthScreen, (int)(0.0984375F * this.mWidthScreen), 0, 0);

And initBackground looks like-

public RelativeLayout initBackground(int intColor, int intWidthscreen, int intHeight, int intMerginLeft, int intMerginTop)
  {
    RelativeLayout localRelativeLayout = new RelativeLayout(this.mContext);
    if (intColor != 0)
    localRelativeLayout.setBackgroundColor(intColor);
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(intWidthscreen, intHeight);
    localLayoutParams.setMargins(intMerginLeft, intMerginTop, 0, 0);
    localRelativeLayout.setLayoutParams(localLayoutParams);
    return localRelativeLayout;
  }

But I need it in rounded shape. something like- enter image description here

I can not use other than RelativeLayout due to project restriction. I also can not use Background XML also. All I need to set from code. I am sorry for that. Any Help will be appreciated.

Upvotes: 0

Views: 1591

Answers (1)

Nisarg Raval
Nisarg Raval

Reputation: 160

GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.RED);
gd.setCornerRadius(10);
gd.setStroke(2, Color.WHITE);

view.setBackground(gd);

Upvotes: 4

Related Questions