【问题标题】:Dynamicly add rows to TableLayout in separated files在单独的文件中将行动态添加到表格布局
【发布时间】:2023-03-12 22:35:01
【问题描述】:

我有这样的东西:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/chooseBirthDateText"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="25dp"
                style="@style/mediumText"
                android:gravity="center_horizontal"
                android:text="@string/choose_birth_date" />

        </TableRow>
    </TableLayout>
</ScrollView>

我想添加更多行,但只能在一段时间后(比如说 10 秒)。我想先让这些行不可见,然后再让它们出现。但是这样我的 scrollView 不能按我的意愿工作(即使下面没有任何内容,我也可以向下滚动 - 因为行是不可见的)

所以我想在第二个文件中创建我想要添加的行,在中间加载它们并在它们必须出现的那一刻添加它们在 tableRow1 之后。不幸的是,我不知道该怎么做(我说的是连接 2 个文件,而不是在 java 中创建第二个文件):/

【问题讨论】:

    标签: java android layout tablerow


    【解决方案1】:

    隐藏视图有两种模式:

    • INVISIBLE:这个视图是不可见的,但它仍然占用空间用于布局。
    • GONE:这个视图是不可见的,它不占用任何空间来布局。

    http://developer.android.com/reference/android/view/View.html#setVisibility(int)

    我认为GONE 会帮助你。

    【讨论】:

    • 哇。惊人的!非常感谢,这比我的要求更好^^
    【解决方案2】:

    你应该这样尝试。让我知道它是否有用?

        for(int i = 0; i < _attributeList.size();i++){
    
    
            TableRow newRow = new TableRow(getApplicationContext());
            newRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    
            newCheckBox = new CheckBox(getApplicationContext());
    
                    TextView feeTypeText = new TextView(getApplicationContext());
                    feeTypeText.setText(jsonObj.getString("feeType"));
                    feeTypeText.setTextColor(Color.BLACK);
                    feeTypeText.setTextSize(16f);
                    feeTypeText.setTypeface(tf);
    
                    TextView dueAmountText = new TextView(getApplicationContext());
                    dueAmountText.setText(jsonObj.getString("dueAmount"));
                    dueAmountText.setTextColor(Color.BLACK);
                    dueAmountText.setTextSize(16f);
                    dueAmountText.setTypeface(tf);
    
                    TextView dueDateText = new TextView(getApplicationContext());
                    dueDateText.setText(jsonObj.getString("dueDate"));
                    dueDateText.setTextColor(Color.BLACK);
                    dueDateText.setTextSize(16f);
                    dueDateText.setTypeface(tf);
    
                    newRow.addView(newCheckBox,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,0.8f)));
                    newRow.addView(feeTypeText,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,0.8f)));
                    newRow.addView(dueAmountText,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,1.0f)));
                    newRow.addView(dueDateText,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,1.0f)));
    

    attributeTable.addView(newRow); }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      相关资源
      最近更新 更多