J'ai une disposition personnalisée qui dessine un rectangle arrondi transparent sous ses enfants. Le problème est quand j'essaye de l'ajouter à mon dossier de xml, il n'apparaît pas. En outre, lorsque j'essaie d'ajouter des paramètres (c'est-à-dire android:layout_width
), la fenêtre contextuelle indique qu'aucun d'entre eux n'est disponible. La même chose arrive à toutes les vues enfant que j'ajoute. Quelqu'un peut-il aider?Écriture personnalisée LinearLayout pour 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);
}
}