Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android LayoutRouble扩展tablerow和膨胀xml tablerow_Android_Android Layout - Fatal编程技术网

Android LayoutRouble扩展tablerow和膨胀xml tablerow

Android LayoutRouble扩展tablerow和膨胀xml tablerow,android,android-layout,Android,Android Layout,我非常接近于选择线性布局,但如果没有正确的选择,会有点恼人。为了获得最大的灵活性,我定义了一个只定义了行标题的TableLayout xml。接下来,我将生成一个单独的TableRowXML,定义“行模板”。在Javacode中,我将TableRow子类化,在构造函数中,我将TableRow模板膨胀到根(子类)上 嗯,到目前为止还不错。填充表格时,headerrow正常,但其他行不正常。看起来它们的布局方式不同,两列没有按预期填充整个宽度,因此列之间没有正确对齐 谁能解释一下这件事?我尝试了很多

我非常接近于选择线性布局,但如果没有正确的选择,会有点恼人。为了获得最大的灵活性,我定义了一个只定义了行标题的TableLayout xml。接下来,我将生成一个单独的TableRowXML,定义“行模板”。在Javacode中,我将TableRow子类化,在构造函数中,我将TableRow模板膨胀到根(子类)上

嗯,到目前为止还不错。填充表格时,headerrow正常,但其他行不正常。看起来它们的布局方式不同,两列没有按预期填充整个宽度,因此列之间没有正确对齐

谁能解释一下这件事?我尝试了很多解决方案,但都没有成功

带有标题行的tablelayout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true" >

        <TableLayout
            android:id="@+id/zone_table"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="fill_horizontal"
                android:clipToPadding="false" >

                <TextView
                    android:layout_width="0dip"
                    android:layout_weight="0.8"
                    android:background="#ffcccccc"
                    android:text="Zonename"
                    android:textColor="@android:color/black" />

                <TextView
                    android:layout_width="0dip"
                    android:layout_weight="0.2"
                    android:background="#ffcccc00"
                    android:gravity="right"
                    android:text="Antall"
                    android:textColor="@android:color/black" />
            </TableRow>
        </TableLayout>
    </HorizontalScrollView>

</ScrollView>

看起来您正在扩展tablerow并创建该对象的实例。这将导致创建一个表行。然后,您正在膨胀另一个tablerow,它出于某种原因与第一个tablerow交互。要快速修复问题,请尝试添加类似table.SetColumnStrestable(0,true)的内容

它看起来像是在扩展tablerow并创建该对象的实例。这将导致创建一个表行。然后,您正在膨胀另一个tablerow,它出于某种原因与第一个tablerow交互。要快速修复问题,请尝试添加类似table.SetColumnStrestable(0,true)的内容

我也有同样的问题。我没有这样做,特别是没有对TableRow进行子类化,只是在代码中实例化它们,并手动将所需的应用于它们。您可以通过封装来实现这一点。有一些包含ZoneInventoryDAO、inventoryCount和tableRow的记录,这些记录指向相应的tableRow实例。只需实例化带有膨胀的TableRow:

TableLayout table = (TableLayout) inflater.inflate(R.layout.my_table, null); // etc
...
for (//each data item//) {
  TableRow tr = (TableRow) inflater.inflate(R.layout.my_table_row, null);
  TextView tv1 = (TextView) findViewById(R.id.table_entry_1);
  tv1.setText("Whatever goes here");
  ...
  // and so on for each column
  table.addView(tr);
}

当我将相同的代码移动到扩展TableRow的类中时,上述方法对我有效。

我也遇到了同样的问题。我没有这样做,特别是没有对TableRow进行子类化,只是在代码中实例化它们,并手动将所需的应用于它们。您可以通过封装来实现这一点。有一些包含ZoneInventoryDAO、inventoryCount和tableRow的记录,这些记录指向相应的tableRow实例。只需实例化带有膨胀的TableRow:

TableLayout table = (TableLayout) inflater.inflate(R.layout.my_table, null); // etc
...
for (//each data item//) {
  TableRow tr = (TableRow) inflater.inflate(R.layout.my_table_row, null);
  TextView tv1 = (TextView) findViewById(R.id.table_entry_1);
  tv1.setText("Whatever goes here");
  ...
  // and so on for each column
  table.addView(tr);
}

当我将相同的代码移动到一个扩展TableRow的类中时,上面的内容对我很有用。

我知道这很旧,但我也遇到了同样的问题,并且解决了这个问题,所以这可能会对未来的用户有所帮助

问题是,当您从XML扩展TableRow并将其添加到扩展TableRow中时,表会将其视为一列,并具有多个子项,因为布局中的TableRow本质上是一个视图组。因此,它将该表作为一个单列表进行布局

解决方案是在TableRow XML布局中,使用
类型,而不是
类型。这样,当膨胀时,xml中的项目将合并到扩展TableRow中,并且扩展TableRow将有多个列

下面是示例代码

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/zonetablerow"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>

    <TextView
        android:id="@+id/zonerow_name"
        android:layout_width="0dip"
        android:layout_weight="0.8"
        android:background="#ffcccccc"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/zonerow_invcount"
        android:layout_width="0dip"
        android:layout_gravity="right"
        android:layout_weight="0.2"
        android:background="#ffcccc00"
        android:textSize="18dp" />

</merge>

我知道这是一个老问题,但我也有同样的问题,并且解决了,所以这可能会帮助未来的用户

问题是,当您从XML扩展TableRow并将其添加到扩展TableRow中时,表会将其视为一列,并具有多个子项,因为布局中的TableRow本质上是一个视图组。因此,它将该表作为一个单列表进行布局

解决方案是在TableRow XML布局中,使用
类型,而不是
类型。这样,当膨胀时,xml中的项目将合并到扩展TableRow中,并且扩展TableRow将有多个列

下面是示例代码

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/zonetablerow"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>

    <TextView
        android:id="@+id/zonerow_name"
        android:layout_width="0dip"
        android:layout_weight="0.8"
        android:background="#ffcccccc"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/zonerow_invcount"
        android:layout_width="0dip"
        android:layout_gravity="right"
        android:layout_weight="0.2"
        android:background="#ffcccc00"
        android:textSize="18dp" />

</merge>