Android 表格行中的列使用权重和;权重计算不能正确地分隔元素

Android 表格行中的列使用权重和;权重计算不能正确地分隔元素,android,android-layout,android-tablelayout,tablerow,android-layout-weight,Android,Android Layout,Android Tablelayout,Tablerow,Android Layout Weight,我被指派创建一个活动,显示按版本对应用程序所做的更改表。该表有四列:Id、类型、说明和版本 为此,我在scrollView中放置了一个TableLayout。然后,我有一个TableRows模板,它在运行时动态膨胀。列宽应保持不变;它们可以在高度上溢出,但不能在宽度上溢出 为了实现这一点,我尝试分别使用列和行容器的weight&weight:sum属性。我已将两个面板上的layout\u width设置为0 问题是这些列正在屏幕边界之外扩展。我会发布这些图片,但我没有权限 (风景看起来很近,但您

我被指派创建一个活动,显示按版本对应用程序所做的更改表。该表有四列:Id、类型、说明和版本

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

为了实现这一点,我尝试分别使用列和行容器的weight&weight:sum属性。我已将两个面板上的
layout\u width
设置为
0

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

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

我注意到,如果孩子们的体重增加到总体重的45%左右,那么体重就接近正常

最后,分隔列的视图的权重为0,宽度为1IP。(我不确定这是否会造成问题)

在我看来,权重就像在横向模式下一样使用宽度。我必须做两个布局,一个用于纵向,一个用于横向

我已经为表行添加了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> 

谢谢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>


David

您可以添加行布局以供参考吗?此外,我还要再次检查各个权重的总和是否真的没有超过中指定的值(我假设您在引用此属性时输入了错误)。