【问题标题】:This LinearLayout layout or its LinearLayout parent is useless这个 LinearLayout 布局或者它的 LinearLayout 父级是没用的
【发布时间】:2014-01-11 18:09:51
【问题描述】:

我收到以下警告:

这个LinearLayout布局或者它的LinearLayout parent是没用的; 将背景属性转移到另一个视图。

不知道是什么问题。阅读其他论坛,但他们没有帮助。有任何想法吗?

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:gravity="bottom"
    android:orientation="vertical" >


<Button
    android:id="@+id/button1"
    android:layout_width="145dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:textStyle="bold"
    android:hint="@string/Play_Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="145dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:textStyle="bold"
    android:hint="@string/Progress_Button" />

<Button
    android:id="@+id/button3"
    android:layout_width="145dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:textStyle="bold"
    android:hint="@string/About_Button" />
</LinearLayout>

</LinearLayout>

【问题讨论】:

    标签: android eclipse


    【解决方案1】:

    您没有使用外部线性布局,因此您可以这样放置 UI:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button1"
        android:layout_width="145dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textStyle="bold"
        android:hint="@string/Play_Button" />
    
    <Button
        android:id="@+id/button2"
        android:layout_width="145dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textStyle="bold"
        android:hint="@string/Progress_Button" />
    
    <Button
        android:id="@+id/button3"
        android:layout_width="145dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textStyle="bold"
        android:hint="@string/About_Button" />
    
    </LinearLayout>
    

    【讨论】:

    • 请记住,您将所有组件都放在您要声明的第一个组件中,可以是 linearLayour、RelativeLayout、Scroolview、ListView 等。
    猜你喜欢
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多