在列的TableRow使用的权重和放大器瓜分; weightsums间距不正确的元素 [英] Columns in a TableRow divided using weights & weightsums not spacing elements properly
问题描述
我是一个新手的Android程序员,我被分配到创建用于显示版本的应用程序所做的更改表的活动。该表有四列,编号,类型,描述和版本。
要做到这一点,我把一个TableLayout在滚动视图。然后,我对TableRows,在运行时动态膨胀的模板。列宽度应保持静止;它们可以在高度溢出,但不宽。
要做到这一点,我尝试使用重量和放大器;重量:分别在列和行容器的总和属性。 (我上都layout_width设置为0)。
的问题是,所述列被扩大屏幕边界之外。我会张贴图片,但我没有权力。
(风景看起来接近,但你可以看到,外疆仍然被切断)。
我注意到,在如果孩子的重量增加至约45%的总的再加权接近寻找合适的。
最后,分离的列的观点已被赋予了权重的零,和1dip宽度。 (我不知道这可能会导致一个问题)。
有何建议?
要我来说,它看起来像加权使用的宽度,如果它是在横向模式。我一定要做出两个布局,一个用于人像,一个景观?
我已经添加了XML布局表格行:
<?XML版本=1.0编码=UTF-8&GT?;
<的TableRow的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的LinearLayout
机器人:ID =@ + ID / table_row_container
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直> <查看
机器人:ID =@ + ID / top_border
机器人:layout_width =match_parent
机器人:layout_height =1dip
机器人:背景=#FFFFFF/> <的LinearLayout
机器人:ID =@ + ID / horizontal_container
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:weightSum =4> <查看
机器人:ID =@ + ID /厂景
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_id
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=ID机器人:TEXTSIZE =10SP机器人:layout_weight =0.5/> <查看
机器人:ID =@ + ID /视图2
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_type
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=类型机器人:TEXTSIZE =10SP机器人:layout_weight =1/> <查看
机器人:ID =@ + ID / VIEW3
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_desc
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=描述机器人:TEXTSIZE =10SP机器人:layout_weight =2/> <查看
机器人:ID =@ + ID / view4
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_version
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=版本机器人:TEXTSIZE =10SP机器人:layout_weight =0.5/> <查看
机器人:ID =@ + ID / view6
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/>
< / LinearLayout中> <查看
机器人:ID =@ + ID / view7
机器人:layout_width =match_parent
机器人:layout_height =1dip机器人:背景=#FFFFFF/> < / LinearLayout中>< /&的TableRow GT;
上下视图是顶部和底部的边界。
和这里是其获取添加过表的布局:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直机器人:scrollbarAlwaysDrawVerticalTrack =真正的> <滚动型
机器人:ID =@ + ID / view_scroll
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT机器人:fillViewport =真正的> < TableLayout
机器人:ID =@ + ID / table_layout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:shrinkColumns =0
机器人:stretchColumns =0>
< / TableLayout> < /滚动型>< / LinearLayout中>
由于MH。
对不起,不又回到了你越快。 (我是新来的Android和堆栈溢出......我不知道你回答我questsion)。我已经添加的行布局。
<?XML版本=1.0编码=UTF-8&GT?;
<的TableRow的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <的LinearLayout
机器人:ID =@ + ID / table_row_container
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直> <查看
机器人:ID =@ + ID / top_border
机器人:layout_width =match_parent
机器人:layout_height =1dip
机器人:背景=#FFFFFF/> <的LinearLayout
机器人:ID =@ + ID / horizontal_container
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:weightSum =4> <查看
机器人:ID =@ + ID /厂景
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_id
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=ID机器人:TEXTSIZE =10SP机器人:layout_weight =0.20/> <查看
机器人:ID =@ + ID /视图2
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_type
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=类型机器人:TEXTSIZE =10SP机器人:layout_weight =0.5/> <查看
机器人:ID =@ + ID / VIEW3
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_desc
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=描述机器人:TEXTSIZE =10SP机器人:layout_weight =1/> <查看
机器人:ID =@ + ID / view4
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/> <的TextView
机器人:ID =@ + ID / txt_version
机器人:layout_width =0dip
机器人:layout_height =WRAP_CONTENT
机器人:文字=版本机器人:TEXTSIZE =10SP机器人:layout_weight =0.25/> <查看
机器人:ID =@ + ID / view6
机器人:layout_width =1dip
机器人:layout_height =match_parent
机器人:背景=#FFFFFF机器人:layout_weight =0.01/>
< / LinearLayout中> <查看
机器人:ID =@ + ID / view7
机器人:layout_width =match_parent
机器人:layout_height =1dip机器人:背景=#FFFFFF/> < / LinearLayout中>< /&的TableRow GT;
大卫
I'm a newbie Android programmer, and I've been assigned to create an activity that displays table of changes made to the app by version. The table has four columns, Id, Type, Description, and Version.
To do this, I placed a TableLayout in a scrollView. Then, I have a template for the TableRows, that are inflated dynamically at Runtime. The column widths should stay static; they can overflow in height but not width.
To achieve this, I tried using the weight & weight:sum property of the column and row container respectively. (I have set the layout_width to zero on both).
The problem is that the columns are expanding outside the screen boundaries. I would post the images but I don't have the authority.
(Landscape looks close but you can see that the outer boundry is still being cut off).
I noticed that in if the weights of the children add to about 45% of the total then the weighting comes close to looking right.
Finally, the views separating the columns have been given a weight of zero, and 1dip width. (I'm not sure if that could be causing a problem).
Any advice?
To me it looks like that weighting is using the width as if it was in landscape mode. Do I have to make two layouts, one for portrait, and one for landscape?
I've added the xml layout for the table row:
<?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>
The upper and lower view are top and bottom borders.
And here is the layout for the table that its getting added too:
<?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>
Thanks MH.
Sorry for not getting back to you sooner. (I'm new to Android and Stack Overflow...and I didn't realize that you answered my questsion.) I've added the row layout.
<?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
这篇关于在列的TableRow使用的权重和放大器瓜分; weightsums间距不正确的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!