I have a custom layout that draws a transparent rounded rectangle beneath its children. The problem is when I try to add it to my xml file, it doesn't show up. Also, when I try to add parameters to it (i.e. android:layout_width
) the popup shows that none of them are available. The same thing happens to any child views I add. Can anyone help?
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);
}
}