2

我想在活动结束时显示一个按钮栏。我创建了一个名为:batton_bar_ref.xml 的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/shape_blue_light_horizental_gradiant_notrounded"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="10dip"
        android:paddingTop="10dip" >

        <Button
            android:id="@+id/pay_button"
            android:layout_width="100dip"
            android:layout_height="50dip"
            android:text="@string/pay"
            android:textSize="16sp"
            android:textStyle="bold" >
        </Button>
    </LinearLayout>

</RelativeLayout>

并将其添加<include layout="@layout/button_bar_ref"/>到另一个布局中。

它显示一条警告消息:

This LinearLayout layout or its RelativeLayout parent is useless; transfer the background attribute to the other view.

你能告诉我我该如何解决吗?

附录:

  1. 按钮栏应该在屏幕的末尾。
  2. 请注意,线性布局有背景。
4

5 回答 5

2

只是建议通过删除不需要的标签来优化您的布局。在您的情况下,由于除了 LinearLayout 之外,RelativeLayout 下没有任何子项,因此此特定布局的设计并不正确。

首先你可以忽略这个警告,一旦你成功地设计了你打算在其中包含这个布局文件的布局文件,你就会意识到这个文件中声明的布局之一可以被消除。

于 2013-06-29T11:08:56.867 回答
1

删除相对布局。

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/shape_blue_light_horizental_gradiant_notrounded"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingBottom="10dip"
        android:paddingTop="10dip" >

    <Button
        android:id="@+id/pay_button"
        android:layout_width="100dip"
        android:layout_height="50dip"
        android:text="@string/pay"
        android:textSize="16sp"
        android:textStyle="bold" >
    </Button>
</LinearLayout>
于 2013-06-29T12:19:03.787 回答
0

请使用以下代码解决您的问题。

<?xml version="1.0" encoding="utf-8"?>

<Button
    android:id="@+id/pay_button"
    android:layout_width="100dip"
    android:layout_height="50dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:text="@string/pay"
    android:textSize="16sp"
    android:textStyle="bold" >
</Button>

于 2013-06-29T12:14:35.370 回答
0

尝试RelativeLayout从 xml 文件中删除标签

于 2013-06-29T11:01:45.720 回答
0

当 Layout 只有一个也是 Layout 的子级时,会触发此警告。在这种情况下,可以毫无问题地删除两者之一。建议删除这些冗余布局,因为它们会降低 UI 的整体性能。

在您的情况下,没有使用RelativeLayout。如果您删除它,则不会有任何变化。所以这个警告正在显示。但这只是一个警告。使用这个没有坏处

于 2013-06-29T11:01:51.543 回答