0

我已被分配创建一个活动,该活动显示按版本对应用程序所做的更改表。该表有四列,Id、Type、Description 和 Version。

为此,我在滚动视图中放置了一个 TableLayout。然后,我有一个 TableRows 模板,它在运行时动态膨胀。列宽应保持不变;它们可以在高度上溢出,但不能在宽度上溢出。

为此,我尝试分别使用列和行容器的 weight & weight: sum 属性。我已经将两者都设置layout_width0

问题是列在屏幕边界之外扩展。我会发布图片,但我没有权限。

(风景看起来很近,但你可以看到外边界仍然被切断)。

我注意到,如果孩子们的体重增加了大约 45%,那么权重就接近正确了。

最后,分隔列的视图的权重为零,宽度为 1dip。(我不确定这是否会导致问题)。

对我来说,加权似乎使用宽度,就好像它处于横向模式一样。我是否必须制作两种布局,一种用于纵向,一种用于横向?

我为表格行添加了 XML 布局:

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

    <LinearLayout
        android:id="@+id/table_row_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <View
            android:id="@+id/top_border"
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:background="#FFFFFF" />

        <LinearLayout
            android:id="@+id/horizontal_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4" >

            <View
                android:id="@+id/view1"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_id"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Id" android:textSize="10sp" android:layout_weight="0.5"/>

            <View
                android:id="@+id/view2"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_type"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Type" android:textSize="10sp" android:layout_weight="1"/>

            <View
                android:id="@+id/view3"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_desc"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Description" android:textSize="10sp" android:layout_weight="2"/>

            <View
                android:id="@+id/view4"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_version"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Version" android:textSize="10sp" android:layout_weight="0.5"/>

            <View
                android:id="@+id/view6"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>
        </LinearLayout>

        <View
            android:id="@+id/view7"
            android:layout_width="match_parent"
            android:layout_height="1dip" android:background="#FFFFFF"/>

    </LinearLayout>

</TableRow>

上视图和下视图是顶部和底部边框。

这是它也被添加的表格的布局:

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

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

        <TableLayout
            android:id="@+id/table_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:shrinkColumns="0"
            android:stretchColumns="0" >
        </TableLayout>

    </ScrollView>

</LinearLayout> 
4

1 回答 1

1

谢谢MH。

很抱歉没有尽快回复您。(我是 Android 和 Stack Overflow 的新手……我没有意识到你回答了我的问题。)我已经添加了行布局。

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

    <LinearLayout
        android:id="@+id/table_row_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <View
            android:id="@+id/top_border"
            android:layout_width="match_parent"
            android:layout_height="1dip"
            android:background="#FFFFFF" />

        <LinearLayout
            android:id="@+id/horizontal_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="4" >

            <View
                android:id="@+id/view1"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_id"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Id" android:textSize="10sp"       android:layout_weight="0.20"/>

            <View
                android:id="@+id/view2"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_type"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Type" android:textSize="10sp" android:layout_weight="0.5"/>

            <View
                android:id="@+id/view3"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_desc"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Description" android:textSize="10sp" android:layout_weight="1"/>

            <View
                android:id="@+id/view4"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>

            <TextView
                android:id="@+id/txt_version"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:text="Version" android:textSize="10sp" android:layout_weight="0.25"/>

            <View
                android:id="@+id/view6"
                android:layout_width="1dip"
                android:layout_height="match_parent"
                android:background="#FFFFFF" android:layout_weight="0.01"/>
        </LinearLayout>

        <View
            android:id="@+id/view7"
            android:layout_width="match_parent"
            android:layout_height="1dip" android:background="#FFFFFF"/>

    </LinearLayout>

</TableRow>

大卫

于 2012-03-06T20:02:40.880 回答