[英]Inflating multiple TextViews on a horizontal LinearLayout
for(int i=0;i<45;i++){
textView[i]=new TextView(context);
iInflateGoesHere.addView(stringArray[i]);//iInflateGoesHere is a horizontal LinearLayout
textView[i].setText(" "+i);
}
結果是:所以它到達行的末尾,嘗試擬合“22”,你可以在截圖上看到結果。
當然,顯示數字不是我的目標,我想從數組添加字符串,因此它看起來像普通文本 - 當一行結束時,文本應該從下一行的開頭。
我怎樣才能實現這一點 - 所以第22行將從第2行開始?
首先,您對論壇用戶的態度非常煩人。 句子如“我知道你不會解決我的問題”或“請你讀我的問題!” 應該避免,因為在這里你可以找到試圖幫助你的人,而不是那些付錢給你服務的人。
說,我認為解決問題的唯一方法是以編程方式獲取屏幕寬度並評估屏幕上可以容納多少TextView,然后使用嵌套的LinearLayout(外部垂直和內部水平)
如果您仍在尋找解決方案,請考慮這可能會有所幫助https://github.com/ApmeM/android-flowlayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:id="@+id/mylayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdfffffffdfaffdffffsffdsffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" >
</TextView>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.