android - make a single button width to fill parent programmatically -
how make single button width fill parent programmatically? have done cannot seem work still located on top left width wrapping content... here of code on button creation...
public class test_gifdisplay extends activity implements view.onclicklistener { surfaceview sview; gifrun gr = new gifrun(); button btnback; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); sview = new surfaceview(this); sview.setzorderontop(true); gr.loadgiff(sview, this, r.drawable.smiley); linearlayout linearlayout1 = new linearlayout(this); linearlayout1.setorientation(linearlayout.vertical); linearlayout1.setbackgroundcolor(color.parsecolor("#27ae60")); linearlayout1.setlayoutparams(new viewgroup.layoutparams( viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content)); linearlayout linearlayout2 = new linearlayout(this); linearlayout2.setorientation(linearlayout.vertical); linearlayout2.setbackgroundcolor(color.parsecolor("#27ae60")); linearlayout2.setlayoutparams(new viewgroup.layoutparams( viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content)); linearlayout.layoutparams p = new linearlayout.layoutparams(linearlayout.layoutparams.fill_parent, linearlayout.layoutparams.wrap_content); p.weight = 1.0f; btnback = new button (this); btnback.settext("back"); btnback.setbackgroundcolor(color.parsecolor("#f1c40f")); btnback.setgravity(gravity.center_horizontal); btnback.setlayoutparams(p); btnback.setonclicklistener(this); linearlayout2.addview(btnback); linearlayout1.addview(linearlayout2); linearlayout1.addview(sview); setcontentview(linearlayout1); } @override public void onclick(view view) { btnback = (button) view; btnback.setbackgroundcolor(color.parsecolor("#2980b9")); //color change new countdowntimer(100, 50) { @override public void ontick(long arg0) { // todo auto-generated method stub } @override public void onfinish() { btnback.setbackgroundcolor(color.parsecolor("#f1c40f")); // original color } }.start();//end color changed finish(); } }
you adding button
linearlayout2
. should change linearlayout2's
width match_parent
linearlayout2.setlayoutparams(new viewgroup.layoutparams( viewgroup.layoutparams.match_parent, viewgroup.layoutparams.wrap_content));
i hope helps.
p.s: can create button's
selectors pressed , selected states, instead of using timer show pressed button effect. here basic link can in achieving : android button selector
Comments
Post a Comment