我有一個自定義佈局,它的子級下繪製一個透明的圓角矩形。問題是當我嘗試將它添加到我的xml文件時,它不顯示。另外,當我嘗試向其添加參數時(即android:layout_width
),彈出窗口顯示它們都不可用。同樣的事情發生在我添加的任何子視圖上。誰能幫忙?編寫自定義LinearLayout爲Android
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);
}
}