android - Change width of a ListView item(row)? -


i have listview every row shows different percentage.

and wanna change 1 of inner layouts width (inside inflated counterview) purpose .

for example:

if first value item in listview 10% width set 10px too

if second value item 50% width change 50px too

something this:
enter image description here

how can ?

i tried these codes doesn't work , width doesn't change: (i defined match_parent width layout inside xml , wanna change programmatically)

public class myadapterscores extends baseadapter {     @override     public view getview(int position, view convertview, viewgroup parent) {         if (convertview == null) {             layoutinflater layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);             convertview  = layoutinflater.inflate(r.layout.scores_layout,null,true);              //i wanna change 'relativelayoutrightsqure' width inside 'scores_layout'             view layout = convertview.findviewbyid(r.id.relativelayoutrightsqure);             viewgroup.marginlayoutparams p = (viewgroup.marginlayoutparams) layout.getlayoutparams();             //variable precentage has value                              p.width=precentage ;             layout.requestlayout(); 

you can't set width percentage think. haven't tested solution, try out! might work!

one solution set width percentage of total width of display maybe:

 windowmanager wm = (windowmanager) getcontext().getsystemservice(context.window_service);     display display = wm.getdefaultdisplay();     point size = new point();     display.getsize(size);     int layoutwidth = size.x * (percentage / 100) 

then can use variable "layoutwidth" set width on layout want.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -