我有一个自定义布局,在其子项下方绘制一个透明的圆角矩形。问题是当我尝试将它添加到我的 xml 文件时,它没有显示出来。此外,当我尝试向它添加参数时(即android:layout_width
),弹出窗口显示它们都不可用。我添加的任何子视图都会发生同样的事情。任何人都可以帮忙吗?
public class RoundRectLayout extends LinearLayout
{
private RectF shape;
public RoundRectLayout(Context context)
{
super(context);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
}
public RoundRectLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.settings, this);
shape = new RectF();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
shape = new RectF(0, 0, w - 5, h - 5);
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void dispatchDraw(Canvas canvas)
{
Paint temp = new Paint();
temp.setAlpha(125);
canvas.drawRoundRect(shape, 10f, 10f, temp);
super.dispatchDraw(canvas);
}
}