Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The view probably <strong>is</strong> getting added, but from the code that you've posted it wouldn't lay out in a way where anything would be visible. By default, when you add a view to a layout in Java code like you have done, without explicitly setting any <code>LayoutParams</code>, it will set your view to be laid out using <code>wrap_content</code> for both height and width. Since (as far as we can see) you are not overriding any of View's measurement methods to tell the layout system how big the "content" inside your custom view is, the view will be added to the hierarchy with a height and width of zero.</p> <p>Before adding your custom view to the layout, you should add a line to set the layout parameters to fill it's container (the parent layout), like so:</p> <pre><code>AbsoluteLayout l= (AbsoluteLayout)findViewById(R.id.ll); DrawView d = new DrawView(this); LayoutParams lp = new AbsoluteLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 0, 0); d.setLayoutParams(lp); l.addView(d); </code></pre> <p>Another option is to add your custom view directly to the XML layout <code>R.layout.e</code>, where you can set all these parameters directly in the XML and not worry about doing it in Java code.</p> <p>Final side note: <code>AbsoluteLayout</code> has been deprecated for a long time now, and should not be used in new applications. You should use a <code>FrameLayout</code> or <code>RelativeLayout</code> for your application, which provide just as much flexibility.</p> <p>HTH</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload