我有一个问题,让我疯狂不同的布局相同的权重得到不同的大小
在我的布局我有两个不同的LinearLayouts。第一个是这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center"
android:text="@string/lblPais" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblJ" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblG" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblP" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblPF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblPC" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblDif" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblPuntos" />
</LinearLayout>
,第二个是这个布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="15" >
<TextView
android:id="@+id/lblPais1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center"
android:text="@string/lblPais" />
<TextView
android:id="@+id/lblJ1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lbl0" />
<TextView
android:id="@+id/lblG1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lbl0" />
<TextView
android:id="@+id/lblP1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lbl0" />
<TextView
android:id="@+id/lblPF1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lbl0" />
<TextView
android:id="@+id/lblPC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lbl0" />
<TextView
android:id="@+id/lblDif1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblPtsVacio" />
<TextView
android:id="@+id/lblPuntos1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/lblPtsVacio" />
</LinearLayout>
正如你可以看到这两种布局得到了layout_width属性(match_parent)相同的值。在两个布局中,我有相同数量的元素(8个TextView)。除第一个TextView外,每个TextView具有相同的权重,权重为8.
如果两个布局相同(只是不同TextView上的标签),为什么它们具有不同的大小?如果你想所有的布局是一样的weight
您orientation
是垂直的,改变我无法理解它,它的驾驶我疯了...
üHV给出的第二布局的机器人:weightSum = 15 – KOTIOS