android - Adding a few TextViews on RelativeLayout -
i'm trying programmatically add many textview relativelayout unable when textview reach end of display right next textview inflate in new line.
relativelayout:
<relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/tag_cloud" android:padding="10dp"> </relativelayout>
code:
if (categoriescursor.movetofirst()){ { textview tagelement = (textview) getlayoutinflater().inflate(r.layout.tag, null); tagelement.settext(categoriescursor.getstring(2)); linearlayout.layoutparams llp = new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content, linearlayout.layoutparams.wrap_content); llp.setmargins(0, 0, pixels, pixels); // llp.setmargins(left, top, right, bottom); tagelement.setlayoutparams(llp); tagcloudlayout.addview(tagelement); } while (categoriescursor.movetonext()); }
tag.xml
<?xml version="1.0" encoding="utf-8"?> <textview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffffff" android:textcolor="#ff000000" android:textstyle="bold" android:paddingleft="5dp" android:paddingright="5dp"/>
thanks
it´s not clear asking, if understand right way, want have 1 line textviews, or? also, using wrong layout params, if want add views relativelayout side side, think with:
relativelayout.layoutparams param = new relativelayout.layoutparams( layoutparams.match_parent, layoutparams.match_parent, 1.0f);
where last parameter stands layout weight attribute. layoutweight , match_parent, views drawn equal size.
Comments
Post a Comment