Android 圆角形状相对长度
我正在安卓项目中进行布局设计。 布局参数以编程方式出现的位置。我当前的布局即将发布- 代码-Android 圆角形状相对长度,android,android-layout,android-drawable,android-relativelayout,Android,Android Layout,Android Drawable,Android Relativelayout,我正在安卓项目中进行布局设计。 布局参数以编程方式出现的位置。我当前的布局即将发布- 代码- mRedBackground=initBackground(getResources().getColor(R.color.transparent_red_80), this.mWidthScreen, (int)(0.0984375F * this.mWidthScreen), 0, 0); 而initBackground看起来像- public RelativeLayout initBackgr
mRedBackground=initBackground(getResources().getColor(R.color.transparent_red_80), this.mWidthScreen, (int)(0.0984375F * this.mWidthScreen), 0, 0);
而initBackground看起来像-
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;
}
但我需要圆形的。类似于-
由于项目限制,我无法使用除RelativeLayout以外的其他工具。我也不能使用背景XML。所有我需要设置的代码。对此我很抱歉。任何帮助都将不胜感激。请参阅
GradientDrawable
请参阅GradientDrawable
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.RED);
gd.setCornerRadius(10);
gd.setStroke(2, Color.WHITE);
view.setBackground(gd);