android - How can I set Imageview and Textview on same line in LinearLayout -


i want set imageview , textview on same line in linearlayout imageview higher textview.

here code:

string b[] = cacbuocthuchien.split("#"); (int j = 0; j < b.length; j++) {     linearlayout.layoutparams lp = new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams.wrap_content);     linearlayout.layoutparams lp2 = new linearlayout.layoutparams(30,30);     lp.setmargins(50, 0, 0, 0);     imageview img = new imageview(recipesdetailactivity.this);     textview tv = new textview(recipesdetailactivity.this);     img.setlayoutparams(lp2);     img.setimageresource(r.mipmap.testic);     tv.setlayoutparams(lp);     tv.settext(b[j] + "\n");     layouthuongdan.addview(img);     layouthuongdan.addview(tv); } 

this can use put image in 1 line.. , work in kind of layouts. hope

  <linerlayout>         <textview         android:id="@+id/text1"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />   <textview         android:id="@+id/text2"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />    ....... // put how many textviews want   <textview         android:id="@+id/textn"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />  </linerlayout> 

you can set visibility gone if wanna show these textviews after setting text. in activity make array of ids of textviews this...

public static int[] textrows = {r.id.text1, r.id.text2, ........ r.id.textn}; 

then use loop initializing them , setting text , images this

   textview[] alltexts = new textview[n];    (int = 0; < n; i++) {         alltexts[i] = (textview) findviewbyid(textrows[i]);         alltexts[i].settext("your text");         alltexts[i].setcompounddrawables(left_image, null, null, null);      } 

it work. try out


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -