Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why would it- you have no data. You created a linear layout and text view, but they aren't your children. So you have no data to draw (and haven't overridden onDraw anyway).</p> <p>If you want to create a custom view that holds a set of other views, you need to derive from ViewGroup, not View. You also need to add the top level subview(s) as children, not just hold them as data members. You're probably even better off deriving directly from LienarLayout or RelativeLayout, and inflating your children directly from xml.</p> <pre><code>public class MoveableMenuLayout extends ViewGroup { public MoveableMenuLayout(Context context, AttributeSet attrs) { super(context, attrs); LinearLayout ll = new LinearLayout(context); ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); TextView tv = new TextView(context); tv.setText("TES_______________"); ll.addView(tv); addView(ll); } public MoveableMenuLayout(Context context) { super(context); LinearLayout ll = new LinearLayout(context); ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); TextView tv = new TextView(context); tv.setText("TES_______________"); ll.addView(tv); addView(ll); } </code></pre> <p>}</p> <p>Will probably work. You can upgrade that to definitely by deriving from LinearLayout instead. And then you wouldn't need to have an internal layout. Like this:</p> <pre><code>public class MoveableMenuLayout extends LinearLayout { public MoveableMenuLayout(Context context, AttributeSet attrs) { super(context, attrs); TextView tv = new TextView(context); tv.setText("TES_______________"); addView(tv); } public MoveableMenuLayout(Context context) { super(context); TextView tv = new TextView(context); tv.setText("TES_______________"); addView(tv); } </code></pre> <p>}</p> <p>An even better way is to do it via xml</p> <pre><code>public class MoveableMenuLayout extends LinearLayout { public MoveableMenuLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater)context.getSystemService( Context.LAYOUT_INFLATER_SERVICE); inflater.inflate( ourlayoutid, this ); } public MoveableMenuLayout(Context context) { super(context); LayoutInflater inflater = (LayoutInflater)context.getSystemService( Context.LAYOUT_INFLATER_SERVICE); inflater.inflate( ourlayoutid, this ); } </code></pre> <p>}</p> <p>and then put the children you want in an xml file. In this case, the top level tag in the xml file should be a tag, not a layout</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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