布局体重问题 [英] Layout weight problem
本文介绍了布局体重问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这已经让我疯狂,我已经尝试了所有类型的其他职务帮助(设置宽度为0dp等),但似乎没有任何工作。
我有2布局,第一个似乎仍然占主导地位:/。如果我把背景coloes上textviews,他们表现自我,最终正确。但是穿上线性布局的背景下,这几乎是屏幕的3/4!?
< XML版本=1.0编码=UTF-8&GT?;
<的TableRow的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT机器人:ID =@ + ID / rowkRow
机器人:背景=@色/ RowBkgColor机器人:重力=center_vertical
机器人:=了minHeight60dp>
< ImageView的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / rowleftImage
机器人:填充=3dip安卓重力=左的android:layout_weight =0/>
<的LinearLayout机器人:方向=垂直
机器人:layout_weight =0的android:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< TextView的Android的:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / rowtext1
机器人:填充=3dip安卓重力=左的Android版本:字体=SANS
机器人:TEXTSTYLE =黑体机器人:文本=一个文本的Android版本:TEXTSIZE =40dp
机器人:文字颜色=#FF333344机器人:能见度=看见
/>
< TextView的Android的:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / rowtext3
机器人:填充=3dip安卓重力=中心的Android版本:字体=SANS
机器人:TEXTSTYLE =黑体机器人:文本=一个文本的Android版本:TEXTSIZE =10dp
机器人:文字颜色=#FF333344机器人:能见度=看见
机器人:后台=#606060
/>
< / LinearLayout中>
<的LinearLayout机器人:方向=垂直
机器人:layout_weight =1机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< TextView的Android的:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / rowtext4
机器人:填充=3dip安卓重力=正确的机器人:文本=四文本
机器人:TEXTSIZE =10dp机器人:TEXTSTYLE =黑体机器人:文字颜色=@色/ RowTextColor
机器人:能见度=看见/>
< TextView的Android的:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / rowtext2
机器人:填充=3dip安卓重力=左的android:文本=第二个文本
机器人:TEXTSIZE =17dp机器人:TEXTSTYLE =黑体机器人:文字颜色=@色/ RowTextColor
/>
< / LinearLayout中>
< ImageView的机器人:ID =@ + ID / rowrightImage
机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
机器人:填充=3dip机器人:layout_weight =0安卓重力=右/>
< /的TableRow>
解决方案
做以下事情。 U可以解决你的问题。
- 将
的android:layout_width
孩子0dp 的
- 将
安卓weightSum
母公司 - 设置了android:每个孩子的layout_weight比例(如
weightSum =5
,三个孩子:layout_weight =1,layout_weight = 3,layout_weight =1
)
This has been driving me crazy i have tried all kinds of help from other posts (setting widths to 0dp etc) but nothing seems to work.
I have 2 layouts and the first one still seems to dominate :/. If i put background coloes on the textviews, they are behaving themselves and end correctly. However put a background on the linear layout and it is almost 3/4 of the screen!?
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/rowkRow"
android:background="@color/RowBkgColor" android:gravity="center_vertical"
android:minHeight="60dp">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/rowleftImage"
android:padding="3dip" android:gravity="left" android:layout_weight="0" />
<LinearLayout android:orientation="vertical"
android:layout_weight="0" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/rowtext1"
android:padding="3dip" android:gravity="left" android:typeface="sans"
android:textStyle="bold" android:text="First Text" android:textSize="40dp"
android:textColor="#FF333344" android:visibility="visible"
/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/rowtext3"
android:padding="3dip" android:gravity="center" android:typeface="sans"
android:textStyle="bold" android:text="First Text" android:textSize="10dp"
android:textColor="#FF333344" android:visibility="visible"
android:background="#606060"
/>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_weight="1" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/rowtext4"
android:padding="3dip" android:gravity="right" android:text="Fourth Text"
android:textSize="10dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
android:visibility="visible" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/rowtext2"
android:padding="3dip" android:gravity="left" android:text="Second Text"
android:textSize="17dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
/>
</LinearLayout>
<ImageView android:id="@+id/rowrightImage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:padding="3dip" android:layout_weight="0" android:gravity="right" />
</TableRow>
解决方案
Do the following things. U can solve your problem.
- set the
android:layout_width
of the children to "0dp" - set the
android:weightSum
of the parent - set the android:layout_weight of each child proportionally (e.g.
weightSum = "5"
, three children:layout_weight="1", layout_weight="3", layout_weight="1"
)
这篇关于布局体重问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文