的LinearLayout layout_weight [英] LinearLayout layout_weight
问题描述
我有一个填充了行一个ListView。这些行来自看起来像一个XML文件:
I have a ListView that is populated with rows. These rows come from an XML file that looks like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dip"
android:weightSum="100">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/columnA"
android:layout_weight="30"
android:layout_gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/columnB"
android:layout_weight="30"
android:layout_gravity="center"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:id="@+id/columnC"
android:layout_weight="10"
android:layout_gravity="center"
>
</ImageView>
<CheckBox
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/columnD"
android:layout_weight="30"
android:layout_gravity="center"/>
问题是我想要的columnC项目,columnB项目非常接近,所以我行三部分等距出来,即:columnA,(columnB + columnC),然后columnD。我试图做到这一点通过layout_weight正如你所看到的,但是上面的code似乎产生相反的效果。 columnA和columnB左侧非常压扁,C列似乎本身就是一个大空间中漂浮,然后columnD靠近columnC,与右太多空间。我究竟做错了什么? :■
The problem is that I want the columnC item and columnB item to be very close together, so that my rows are equally spaced out in three parts, i.e.: columnA, (columnB+columnC) and then columnD. I tried to achieve this by using layout_weight as you can see, however the above code seems to have the opposite effect. columnA and columnB are very squished on the left, column C seems to be floating in a large space on its own, and then columnD is located close to columnC, with too much space on its right. What am I doing wrong? :s
推荐答案
我想你想columnC和columnB具有相同的重量,但你有它设置与他们不同。
I would think that you want columnC and columnB to have the same weight, but you have it set with them different.
尝试
columnA:体重= 2
columnA:weight=2
columnB:体重= 1
columnB:weight=1
columnC:体重= 1
columnC:weight=1
columnD:体重= 2
columnD:weight=2
我与权重属性的经验非常有限,但我认为这是你可以得到你想要的结果。
I have very limited experience with the weight attribute but I think this is how you can get your desired result.
如果你还在用起来麻烦,可以帮助我们来帮助你,如果你能张贴它的外观的屏幕截图,你想怎么看。
If you're still having trouble with it, may help us help you if you can post a screen shot of how it looks, and how you want it to look.
这篇关于的LinearLayout layout_weight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!