2011-07-05 60 views
7

現在,這裏是佈局我的XML代碼相對佈局不低於越來越

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

     <RelativeLayout 
         android:id="@+id/RelativeLayout01" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"> 
      <ImageView 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:background="@drawable/default1" 
         android:id="@+id/default1" 
         android:layout_gravity="center" 
         android:scaleType="fitXY"> 
      </ImageView> 

      <ImageView 
         android:layout_marginTop="19dp" 
         android:layout_width="180dp" 
         android:layout_height="45dp" 
         android:src="@drawable/fc_postyour_best_score_bg" 
         android:id="@+id/postscore" 
         android:layout_alignParentRight="true" 
         android:scaleType="fitXY"> 
      </ImageView> 

      <ImageButton 
         android:layout_marginTop="22dp" 
         android:layout_width="35dp" 
         android:layout_height="35dp" 
         android:background="@drawable/fctwitterup" 
         android:layout_marginLeft="7dp" 
         android:id="@+id/twitter" 
         android:layout_alignRight="@id/postscore" 
         android:scaleType="fitXY"> 
      </ImageButton> 

      <ImageButton 
         android:layout_marginTop="22dp" 
         android:layout_width="35dp" 
         android:layout_height="35dp" 
         android:background="@drawable/fcfacebookdown" 
         android:id="@+id/fb" 
         android:layout_toLeftOf="@id/twitter"> 
      </ImageButton> 

      <ImageButton 
         android:layout_width="160dp" 
         android:layout_height="40dp" 
         android:background="@drawable/fsremove_ads_down" 
         android:id="@+id/fsremove_ads_down"      
         android:layout_below="@id/postscore" 
         android:layout_alignParentRight="true" 
         android:layout_marginBottom="3dp"> 
      </ImageButton> 

      <ToggleButton 
         android:id="@+id/fsvibrate_on" 
         android:layout_width="135dip" 
         android:layout_height="35dip" 
         android:textOff="" 
         android:textOn="" 
         android:layout_below="@+id/fsremove_ads_down" 
         android:layout_alignParentRight="true" 
         android:background="@drawable/fsvibrate_on"> 
      </ToggleButton> 

      <ImageButton 
         android:layout_width="210dp" 
         android:layout_height="60dp" 
         android:background="@drawable/fcplaydown" 
         android:id="@+id/fcplaydown" 
         android:layout_centerInParent="true"> 
      </ImageButton> 

      <ToggleButton 
         android:id="@+id/fcsoundondown" 
         android:layout_width="35dp" 
         android:layout_height="35dp" 
         android:textOff="" 
         android:textOn="" 
         android:layout_below="@+id/fcplaydown" 
         android:background="@drawable/fcsoundondown"> 
      </ToggleButton> 


     </RelativeLayout> 

</LinearLayout> 

所以我的問題是@+id/fcsoundondown切換按鈕,我已經設置爲低於@+id/fcplaydown但不低於來到指定的按鈕,但在"@+id/postscore"

+0

你能分享一個截圖來說明你的問題嗎? – Udayan

回答

12

我不知道要很好地解釋,爲什麼出現這種情況,但它關係到你的設置@+id/fcplaydown ImageButton父居中,和他的父母是與WRAP_CONTENT的寬度和高度,在一個RelativeLayout的佈局只是感到困惑。

因此,將RelativeLayout設置更改爲match_parent,它將起作用。

<RelativeLayout 
    android:id="@+id/RelativeLayout01" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"> 
+0

感謝這個工程,但現在我想把一個按鈕右側@ + id/fcsoundondown,但它似乎在屏幕的頂部可以你引導我??? –

+0

\t \t

+0

安卓layout_toRightOf只設置水平的位置,你必須添加其他屬性來設置它的垂直位置也說不定的機器人: layout_alignTop =「@ id/fcsoundondown」或android:layout_alignBottom =「@ id/fcsoundondown」,或兩者兼有,具體取決於您的喜好 – Adinia

-1

@ + id只有在您爲元素分配新ID時才應使用。而當你指的是一個元素使用@id

字符串開頭的at符號(@)表示XML解析器應該解析並展開ID字符串的其餘部分,並將其標識爲ID資源。加號(+)表示這是一個新的資源名稱,必須創建並添加到我們的資源中(在R.java文件中)。

參考:http://developer.android.com/guide/topics/ui/declaring-layout.html#id

+1

okk okkk我已經改變了,但我的問題仍然存在,請給出任何竅門 –

0

佈局視圖標識符用於關聯位置和大小。現在,當一個id被定義時,它被存儲在R.java中。我們都知道。那麼,我們不知道的是,RelativeLayout中的視圖是由多個佈局文件的解析構建而成的。考慮到編譯是一個昂貴的過程,並且需要優化此過程,所以Android需要使用+符號重置id,當您想使用它時,不僅在您聲明它時。即使它有點混亂,這是如何被使用。