Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 圆角形状相对长度_Android_Android Layout_Android Drawable_Android Relativelayout - Fatal编程技术网

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);