跨度的TableRow不工作的动态添加的行 [英] TableRow span not working for dynamically added rows

查看:167
本文介绍了跨度的TableRow不工作的动态添加的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题跨越动态添加行滚动视图内TableLayout。该行遵循这个模式:

I have the following problem spanning dynamically added rows to a TableLayout inside a scroll view. The rows follow this pattern:

第1行:单元格跨越了整个表
第2行:两个单元格
第3行:单元格跨越了整个表
...
行N:两个单元

Row 1: Cell spanned over the whole table
Row 2: Two cells
Row 3: Cell spanned over the whole table
...
Row N: Two cells

存在的问题是,与一个小区跨越了该行的行实际上不会跨越在所有。它达到在屏幕的中间的一些点和只是包装在高度

The problems is that the row with the one cell spanning over the row actually does not span at all. It reaches at some point in the middle of the screen and just wraps at height.

下面的是Android 2.3.3根据问题的截图:

Here is a screenshot of the problem under Android 2.3.3:

请注意,以下的样品被简单化(但仍跨越不工作)。他们准备尝试 - 刚刚创建的文件。我调试,似乎布局PARAMS在某种程度上沿途消失。此外,如果TableLayout是硬codeD在main.xml中的文件,则没有问题。不幸的是,我需要有意见动态生成的。

Note that the samples below are oversimplified (but still spanning does not work). They are ready to try - just create the files. I debugged and it seems that the layout params are somehow disappearing along the way. Additionally, if the TableLayout is hard-coded in the main.xml file, then there are no problems. Unfortunately, I need to have views dynamically generated.

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class TestProject extends Activity {
        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                TableLayout table = new TableLayout(this);
                ScrollView contentHolder = (ScrollView) findViewById(R.id.scrollView1);
                contentHolder.addView(table, new TableLayout.LayoutParams(
                        TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
                TableRow row1 = (TableRow) View.inflate(this, R.layout.table_span_row, null);
                TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(
                        TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
                rowSpanLayout.span = 2;
                table.addView(row1, rowSpanLayout);
                TableRow row2 = (TableRow) View.inflate(this, R.layout.table_row_columns, null);
                table.addView(row2);
                    }
    }

的main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">

<ScrollView android:id="@+id/scrollView1" android:layout_height="fill_parent"
    android:layout_width="fill_parent">
</ScrollView>
</LinearLayout>

table_row_columns.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content" android:text="This is column one" android:layout_weight="1" android:layout_width="fill_parent"></TextView>
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Column 2"></TextView>
</TableRow>

table_span_row.xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="wrap_content" android:layout_width="fill_parent">
    <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_span="2" android:background="#FF333333">
        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="This should span on the whole row"></TextView>
        <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="... but it does not do so"></TextView>
    </LinearLayout>
</TableRow>

我已经试过requestLayout和失效,但无济于事。

I have tried requestLayout and invalidate but to no avail.

P.S。我也欢迎建议有关如何动态的滚动型

P.S. I also welcome advises about how to dynamically replace views within the ScrollView

推荐答案

OK,我找到了解决办法。它只是砸的TableRow标签,我想整个表跨越行。

OK, I found the solution. It was simply to drop the TableRow tag for the row that I wanted to span across the table.

table_span_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:background="#FF333333">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_weight="1" android:text="This should span on the whole row" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="... and now it does" />
</LinearLayout>

我不知道,如果我有3列,而不是与想跨越其中一个细胞对他们俩会发生什么:)

I do not know what will happen if I had 3 columns instead and wanted to span one of the cells on two of them :)

这篇关于跨度的TableRow不工作的动态添加的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆