android - Custom Relative layout not rendering any children -


intro:

i attempting add various views custom relativelayout, i.e. buttons, imageviews, etc none of them render/show.

documentation:

as shown on numerous questions: here, here, here, here , many more,

i have standard requirements extending layout, i.e. 3 constructors, being:

public relativelayout(context context) {}  public relativelayout(context context, attributeset attrs) {}  public relativelayout(context context, attributeset attrs, int defstyleattr){} 

referred here on android developer site.


implementation:

my relativelayout named diceroller has following implementation:

public class diceroller extends relativelayout {      private diecontainer diecontainer;     private context mcontext;     private int speed;     private runnable movedies;     private handler handler;     private timer timer;      public diceroller(context context) {         super(context);         mcontext = context;         init();     }      public diceroller(context context, attributeset attrs) {         super(context, attrs);         mcontext = context;         init();     }      public diceroller(context context, attributeset attrs, int defstyleattr) {         super(context, attrs, defstyleattr);         mcontext = context;         init();     }  private void init() {          //source : https://stackoverflow.com/questions/28265286/custom-relative-layout-not-showing-child-views          setlayoutparams(new layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent));          setgravity(gravity.center);         imageview mainimage = new imageview(mcontext);         mainimage.setid(1994);         layoutparams params = new layoutparams(100, 100);          mainimage.setimageresource(r.drawable.die1);         mainimage.setlayoutparams(params);          addview(mainimage);          relativelayout.layoutparams crossparams = new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content);          crossparams.addrule(relativelayout.align_top | relativelayout.align_left, mainimage.getid());         imageview crossimage = new imageview(mcontext);         crossimage.setimageresource(r.drawable.die6);         crossimage.setlayoutparams(crossparams);          addview(crossimage);          textview tv = new textview(mcontext);          tv.settext("hello world");          addview(tv);     } } 

please note: contents of init() method purely test if views infact rendered. last attempt @ debugging issue, added views mainactivity aswell, without success

with associated layout file

<?xml version="1.0" encoding="utf-8"?> <com.myapp.diceroller         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:tools="http://schemas.android.com/tools"         xmlns:app="http://schemas.android.com/apk/res-auto"         android:layout_width="1000px"         android:layout_height="1000px"         android:background="@color/coloraccent"         android:id="@+id/rollerback"> </com.myapp.diceroller> 

what problem:

the problem simple. no child of layout rendered/shown/visible.

i attempted adding child in mainactivity, programmatically. did not render. attempted adding child within relativelayout class, did not render.

additional info:

note: when adding views, added text or image, set x, y values, included relativelayout.layoutparams() wrap option set.

when debugging issue, if added view (imageview, button, etc), layout has each child stored, , each child's parent relativelayout. each child has width, height, x, y value , content (either image or text), problem not lie children.

i @ loss, have no idea why doesn't render, appreciated!


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -