android - Getting RelativeLayout to work correctly at runtime -


i'm trying use relativelayout produce 2 rows of items, 1 row of 3 buttons top scrollview below them. want scrollview occupy of space possible.

i believe relativelayout best approach here. i'm trying @ runtime , not via xml layout file. code follows:

            relativelayout.layoutparams exitparams = new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent,                       relativelayout.layoutparams.wrap_content);                exitparams.addrule(relativelayout.align_parent_left);                relativelayout.layoutparams zimparams = new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent,                       relativelayout.layoutparams.wrap_content);              relativelayout.layoutparams zoutparams = new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent,                       relativelayout.layoutparams.wrap_content);              relativelayout.layoutparams scrollparams = new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent,                       relativelayout.layoutparams.wrap_content);              zimparams.addrule(relativelayout.align_parent_right);              scrollparams.addrule(relativelayout.align_parent_bottom):                 // exit button             button exitbutton = new button(this);             exitbutton.settext("exit");             exitbutton.setgravity(gravity.center);             exitbutton.setwidth(200);             exitbutton.setlayoutparams(exitparams);               // zoom in button             button zoomoutbutton = new button(this);             zoomoutbutton.settext("zoom out");             zoomoutbutton.setgravity(gravity.center);             zoomoutbutton.setwidth(200);             zoomoutbutton.setlayoutparams(zimparams);               // zoom in button             button zoominbutton = new button(this);             zoominbutton.settext("zoom in");             zoominbutton.setgravity(gravity.center);             zoominbutton.setwidth(200);             zoutparams.addrule(relativelayout.left_of, zoominbutton.getid());                zoominbutton.setlayoutparams(zoutparams);              relativelayout layout1 = new relativelayout(this);               layout1.setlayoutparams(new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent, relativelayout.layoutparams.fill_parent));               layout1.addview(exitbutton);               layout1.addview(zoominbutton);               layout1.addview(zoomoutbutton);                    exitbutton.setonclicklistener (new view.onclicklistener() {                 public void onclick(view v) {                    finish();                 }             });              zoominbutton.setonclicklistener (new view.onclicklistener() {                 public void onclick(view v) {                     increasezoom();                     onresume();                    }             });              zoomoutbutton.setonclicklistener (new view.onclicklistener() {                 public void onclick(view v) {                    reducezoom();                    onresume();                    }             });              drawview = new drawview(this, height, width, smd, zoomlevel);             drawview.setbackgroundcolor(color.white);             scrollview scrollview = new scrollview(this);             scrollview.addview(drawview);             scrollview.setlayoutparams(scrollparams);              layout1.addview(scrollview);             setcontentview(layout1); 

yet thing shows scrollview. i'm guessing i'm missing small here... read documentation , believe did correctly fact not working suggests either did wrong or cannot accomplish want do.

a visual of how want follows:

layout

you need call setcontentview(layout1) @ end add layout.

edit:

okay iv'e fixed code , it's working on phone. couldn't' work drawview if there wrong can't you. give go.

     relativelayout.layoutparams exitparams = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,                relativelayout.layoutparams.wrap_content);         exitparams.addrule(relativelayout.align_parent_left);         relativelayout.layoutparams zimparams = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,                relativelayout.layoutparams.wrap_content);       relativelayout.layoutparams zoutparams = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,                relativelayout.layoutparams.wrap_content);       relativelayout.layoutparams scrollparams = new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent,                relativelayout.layoutparams.wrap_content);       zimparams.addrule(relativelayout.align_parent_right);           // exit button      button exitbutton = new button(this);      exitbutton.settext("exit");      exitbutton.setgravity(gravity.center);      exitbutton.setwidth(200);      exitbutton.setlayoutparams(exitparams);      exitbutton.setid(2);        // zoom in button      button zoomoutbutton = new button(this);      zoomoutbutton.settext("zoom out");      zoomoutbutton.setgravity(gravity.center);      zoomoutbutton.setwidth(200);      zoomoutbutton.setlayoutparams(zimparams);      zoomoutbutton.setid(1);       // zoom in button      button zoominbutton = new button(this);      zoominbutton.settext("zoom in");      zoominbutton.setgravity(gravity.center);      zoominbutton.setwidth(200);      zoutparams.addrule(relativelayout.left_of, 1);        zoutparams.addrule(relativelayout.right_of, 2);         zoominbutton.setlayoutparams(zoutparams);       relativelayout layout1 = new relativelayout(this);        layout1.setlayoutparams(new relativelayout.layoutparams(relativelayout.layoutparams.fill_parent, relativelayout.layoutparams.fill_parent));        layout1.addview(exitbutton);        layout1.addview(zoominbutton);        layout1.addview(zoomoutbutton);             exitbutton.setonclicklistener (new view.onclicklistener() {          public void onclick(view v) {             finish();          }      });       zoominbutton.setonclicklistener (new view.onclicklistener() {          public void onclick(view v) {              //increasezoom();              onresume();             }      });       zoomoutbutton.setonclicklistener (new view.onclicklistener() {          public void onclick(view v) {             //reducezoom();             onresume();             }      });       //drawview = new drawview(this, height, width, smd, zoomlevel);     // drawview.setbackgroundcolor(color.white);      scrollview scrollview = new scrollview(this);      //scrollview.addview(drawview);      scrollparams.addrule(relativelayout.below,1);      scrollview.setlayoutparams(scrollparams);       layout1.addview(scrollview);      setcontentview(layout1); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -