Problem with setLayoutParams method in android UI -


i making application in have change ui programmaticaly. needed change layout_height , layout_width xml attributes.

but when use setlayoutparams method, app runs , give message has unexpectedly stopped working , have force close.

i have tried setting layoutparams viewgroup.layoutparams well. nothing works. kindly check attached code , guide.

this java code.

private void fixlayoutvmain(){     listview lv;     imagebutton rev,stop,play,forw;     lv=(listview)findviewbyid(r.id.listmain);     rev=(imagebutton)findviewbyid(r.id.rev);     stop=(imagebutton)findviewbyid(r.id.stop);     play=(imagebutton)findviewbyid(r.id.plpa);     forw=(imagebutton)findviewbyid(r.id.forw);     log.d("dev1","id's have been assigned");     layoutparams lp=new layoutparams(w, ((75*h)/100));           log.d("dev1","param object created");            lv.setlayoutparams(lp);          log.d("dev1","listview param set");          lp.height=(int)(10*h)/100;     lp.width=(int)(10*h)/100;     log.d("dev1","changes param made");     rev.setlayoutparams(lp);         log.d("dev1","reverse button param applied");     stop.setlayoutparams(lp);     log.d("dev1","stop button param applied");     play.setlayoutparams(lp);     log.d("dev1","forward button param applied");     forw.setlayoutparams(lp);     log.d("dev1","all imagebutton changes have been made");  } 

this xml file

<linearlayout     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent">     <listview         android:id="@+id/listmain"         android:layout_width="fill_parent"         android:layout_height="wrap_content" />         <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"             android:orientation="horizontal"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:gravity="bottom">             <imagebutton                 android:id="@+id/rev"                 android:src="@drawable/reverseimg"                 android:background="@null"                 android:scaletype="fitxy" />             <imagebutton                 android:id="@+id/stop"                 android:src="@drawable/stopimg"                 android:background="@null"                 android:scaletype="fitxy" />             <imagebutton                 android:id="@+id/plpa"                 android:src="@drawable/playimg"                 android:background="@null"                 android:scaletype="fitxy" />             <imagebutton                 android:id="@+id/forw"                 android:src="@drawable/forwardimg"                 android:background="@null"                 android:scaletype="fitxy" />     </linearlayout> </linearlayout> 

any time set layoutparams, check parent container of view. in instances, parent linearlayout. need use linearlayout.layoutparams, so:

linearlayout.layoutparams lp = new linearlayout.layoutparams(width, height); lv.setlayoutparams(lp); 

whether that's particular force close issue or not, have no way of knowing. stated in comments, should check logcat , post exception details here. give try though, , see if fixes problem.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -