有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在水平线性布局上扩展多个文本视图

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号线的起点开始

enter image description here


共 (3) 个答案

  1. # 1 楼答案

    <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>
    
  2. # 3 楼答案

    首先,你对论坛用户的态度很烦人。像“我知道你不会解决我的问题”或“请读我的问题!”应该避免,因为在这里你可以找到试图帮助你的人,而不是付钱给你提供服务的人

    尽管如此,我认为解决问题的唯一方法是通过编程获得屏幕的宽度,并评估屏幕上可以容纳多少文本视图,然后使用嵌套的LinearLayout(外部垂直和内部水平)