机器人:layout_weight初学者的问题 [英] android:layout_weight beginner's question
问题描述
在我的下面,它显示了四种颜色顶部的布局有很大的面积小于底部布局区域。
据<一href="http://developer.android.com/guide/topics/ui/layout-objects.html#linearlayout">http://developer.android.com/guide/topics/ui/layout-objects.html#linearlayout,当你添加更多的layout_weight,它应该增加面积,但它在code下降。
任何帮助将AP preciated。
在此先感谢。
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT&GT;
&LT;的LinearLayout
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =4&GT;
&LT;的TextView
机器人:文本=红
机器人:重力=center_horizontal
机器人:后台=#AA0000
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =3/&GT;
&LT;的TextView
机器人:文本=绿色
机器人:重力=center_horizontal
机器人:后台=#00aa00
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1/&GT;
&LT;的TextView
机器人:文本=蓝
机器人:重力=center_horizontal
机器人:后台=#0000aa
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1/&GT;
&LT;的TextView
机器人:文本=黄
机器人:重力=center_horizontal
机器人:后台=#aaaa00
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1/&GT;
&LT; / LinearLayout中&GT;
&LT;的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_weight =1&GT;
&LT;的TextView
机器人:文本=行的一个
机器人:TEXTSIZE =15pt
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/&GT;
&LT;的TextView
机器人:文本=连续两年
机器人:TEXTSIZE =15pt
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/&GT;
&LT;的TextView
机器人:文本=排三
机器人:TEXTSIZE =15pt
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/&GT;
&LT;的TextView
机器人:文本=四大行
机器人:TEXTSIZE =15pt
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1/&GT;
&LT; / LinearLayout中&GT;
&LT; / LinearLayout中&GT;
我有同样的问题。诀窍是不要使用WRAP_CONTENT或FILL_PARENT的重要设置的控制。相反设置layout_height为0px(在垂直布局时),然后将子控件将获得每重量值匀称。
When I have the following, it shows top layout with four colors has much smaller area than the bottom layout area.
According to http://developer.android.com/guide/topics/ui/layout-objects.html#linearlayout, when you add more to layout_weight, it should increase the area, but it decreases in the code.
Any help will be appreciated.
Thanks in advance.
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="4">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="3"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
I had the same problem. The trick is not to use "wrap_content" or "fill_parent" for the controls you are setting a weight to. Instead set the layout_height to 0px (when inside a vertical layout) and then the child controls will get proportioned per the weight values.
这篇关于机器人:layout_weight初学者的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!