2014-03-29 71 views
1

我得到的Android應用程序謨以下警告在Eclipse上:的Android/Eclipse的:這個的LinearLayout佈局或其RelativeLayout的父母可能是無用

This LinearLayout layout or its RelativeLayout parent is possibly useless

想不通的問題是什麼。閱讀其他論壇,但他們沒有幫助。有任何想法嗎?

下面的代碼:

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

    <LinearLayout 
     android:id="@+id/lin_progress_bar" 
     android:layout_width="200dp" 
     android:layout_height="65dp" 
     android:layout_marginLeft="60dp" 
     android:layout_marginTop="150dp" 
     android:visibility="invisible" > 

     <ProgressBar 
      android:id="@+id/ProgressBar01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 
     </ProgressBar> 

     <TextView 
      android:id="@+id/TextView01" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="30dp" 
      android:layout_marginTop="5dp" 
      android:gravity="center_vertical" 
      android:text="@string/loading" 
      android:textColor="#808080" 
      android:textSize="17sp" 
      android:textStyle="bold" > 
     </TextView> 
    </LinearLayout> 

</RelativeLayout> 
+0

這真是沒用茨艾倫有兩個嵌套的容器。我會刪除LinearLayout(我總是喜歡RelativeLayouts)。 –

+0

請勿使用硬編碼的'layout_width's和'layout_height's。你的應用程序將運行在各種設備上,如果你使用硬編碼值,你可能不會總是得到相同的外觀。儘量使用標準的'match_parent'和'wrap_content'和layout_weights。 –

回答

1

這是你的佈局的簡化版本:

<?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" 
    > 
    <ProgressBar 
     android:id="@+id/ProgressBar01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="60dp" 
     android:layout_marginTop="150dp" 
     android:visibility="invisible" 
    /> 
    <TextView 
     android:id="@+id/TextView01" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="30dp" 
     android:layout_marginTop="5dp" 
     android:gravity="center_vertical" 
     android:text="@string/loading" 
     android:textColor="#808080" 
     android:textSize="17sp" 
     android:textStyle="bold" 
    /> 
</RelativeLayout> 

現在,它已經獲得了平整度 - 這是翻譯更好的性能

0

錯誤消息意味着RelativeLayout的包含其中包含實際的小部件的LinearLayout:這將是更有效的去除相對佈局和僅使用的LinearLayout。

請注意,這是一個警告,您有時需要一個無用的佈局來讓您的應用按照您想要的方式(儘管我沒有遇到過這些情況)。

相關問題