android - Programatically LinearLayout Weight -


I'm trying to grow like a grid, but using LinearLayout . I want to read 3 images after the images in a row and exact below.

Enter the image here

What I have tried :

  LinearLayout layout = new LinearLayout (reference); Layout.setOrientation (LinearLayout.VERTICAL); ImageView icon = New ImageView (reference); Item item = getItem (page, index); Logs. E ("tag", item .getDrawable ()); imageLoader.displayImage (item.getDrawable (), icon, R.drawable.ic_launcher); Icon.setPadding (15, 15, 15, 15); Layout.addView (icon); Textview label = new textview (reference); Label.setTag ("text"); Label.setText (item.getName ()); Label.setTextColor (Color.BLACK); the label. Setgravity (Gravity tapes | Gravity CNTAROSISOSOA); Label.setLayoutParams (new layout paragraph (layout paramount. MATCH_PARENT, paragraph layout. WRAP_CONTENT)); Layout.setLayoutParams (New LinearLayout.LayoutParams (Layout P.WRAP_CONTENT, Layout Para. WRAP_CONTENT)); layout.setWeightSum (3F); Layout.addView (label);   

I have a visual method that gives view , so I'll take back; At the end of the law; Here I have given the weight 3 button which is not working for me.

Any help would be appreciated.

Thank you.

I have a tablelayout < / Code> as many as tableRow s, I need to define. On each of those TableRows , I used the LinearLayout with respect to the VERTICAL two view ImageView < / code> and TextView .

This is LinearLayout where you have to get the width of the screen and make sure that the new linear timepieces < Adding / code> still fits in the existing row if not, just start a new TableRow .

You can use it to get the width of the screen:

  last display display = getWindowManager () .getDefaultDisplay (); Last point size = new point (); Display.getSize (size); Final Window Manager. Layout Parameters = The Window (). GetAttributes ();   

The width of the screen can be accessed through the params.width attribute, just copy it to its LinearLayout compare to. To keep an incremental account of the GetWidth () method and the current TableRow width (a float ), help you determine whether the current item Should be placed an existing line or a new one

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -