嵌套的权重是不好的表现,我的XML code [英] Nested weights are bad for performance in my XML code
问题描述
我要显示一个有组织的网格。所以我使用的LinearLayout和布局权重的选择,每一件事情完美的作品,但我不知道如何避免和此警告在该按钮的按键C:
I want to display an organized grid. So I use LinearLayout and Layout Weight option, every thing works perfectly, but I don't understand how to avoid this warning in the Button A and the Button C:
Nested weights are bad for performance
这是我的XML code:
And this is my XML code :
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- First row. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="A" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="B" />
</LinearLayout>
<!-- Second row. -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="C" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="D" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
我怎样才能避免这种错误吗?
How can I avoid this error please ?
推荐答案
您只能如果你想保持这种布局忽略此警告。
You can only ignore this warning if you want to keep this layout.
添加到您的布局根:的xmlns:工具=http://schemas.android.com/tools
。然后在你的按钮添加工具:忽略=NestedWeights
Add to the root of your layout: xmlns:tools="http://schemas.android.com/tools"
. Then in your buttons add tools:ignore="NestedWeights"
.
这也可以通过将光标放在黄线和pressing做在eclipse CTRL + 1
。您可以选择忽略。
This can be also done in eclipse by putting the cursor on the yellow line and pressing ctrl + 1
. You can choose ignore.
如果你想提高性能,你可以使用TableLayout
If you want to improve performance, you can use a TableLayout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:padding="5dip" >
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="A" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="B" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:padding="5dip" >
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="C" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="D" />
</TableRow>
</TableLayout>
这篇关于嵌套的权重是不好的表现,我的XML code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!