2012-10-04 36 views
2

我想在屏幕上有兩個相對佈局。一個在下面。我做了這段代碼,但它不起作用。在這種情況下,我只能看到兩個上面的相對佈局insted,這個佈局佔用了整個空間,儘管我設置了wrap_content。一個屏幕上的兩個相對佈局

編輯!:我把下面的第二個代碼也失敗了。

編輯2!:我發現問題......這有點...傷心。問題在於我的主題。我將背景設置爲太大的png文件,當我通過清單應用默認主題時,發生這種情況。當我刪除它一切都很好。

此版本也失敗。

新代碼:

<RelativeLayout 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" > 

    <RelativeLayout 
     android:id="@+id/some_id" 
     android:layout_above="@+id/some_id2" 
     android:layout_alignParentTop="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/main_button_localize" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/main_localize" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:id="@id/some_id2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <ToggleButton 
      android:id="@+id/main_help" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

</RelativeLayout> 

舊代碼:

<RelativeLayout 
    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" > 

    <RelativeLayout 
     android:id="@+id/maps_manager_menu" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" > 

     <!-- Top --> 
     <Button 
      android:id="@+id/maps_manager_top_left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/empty" /> 

     <Button 
      android:id="@+id/maps_manager_top_middle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/maps_manager_top_left" 
      android:contentDescription="@string/empty" /> 

     <Button 
      android:id="@+id/maps_manager_top_right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/maps_manager_top_middle" 
      android:contentDescription="@string/empty" /> 

     <!-- Middle --> 
     <Button 
      android:id="@+id/maps_manager_middle_left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/maps_manager_top_left" 
      android:contentDescription="@string/empty" /> 

     <Button 
      android:id="@+id/maps_manager_middle_middle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/maps_manager_middle_left" 
      android:layout_below="@id/maps_manager_top_middle" 
      android:contentDescription="@string/empty" /> 

     <Button 
      android:id="@+id/maps_manager_middle_right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/maps_manager_middle_middle" 
      android:layout_below="@id/maps_manager_top_right" 
      android:contentDescription="@string/empty" /> 

     <!-- Bottom --> 
     <Button 
      android:id="@+id/maps_manager_bottom_left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/maps_manager_middle_left" 
      android:contentDescription="@string/empty" /> 

     <Button 
      android:id="@+id/maps_manager_bottom_middle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/maps_manager_bottom_left" 
      android:layout_below="@id/maps_manager_middle_middle" 
      android:contentDescription="@string/empty" /> 

     <Button 
      android:id="@+id/maps_manager_bottom_right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/maps_manager_bottom_middle" 
      android:layout_below="@id/maps_manager_middle_right" 
      android:contentDescription="@string/empty" /> 

    </RelativeLayout> 

    <RelativeLayout 
      android:id="@+id/maps_manager_controls" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="true" 
      android:layout_below="@id/maps_manager_menu" > 

      <ToggleButton 
       android:id="@+id/maps_manager_help" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </RelativeLayout> 

</RelativeLayout> 
+0

我檢查Eclipse的,我能看到兩個相對佈局一個在另一個之下。 –

+0

在第二個相對佈局中將match_parent更改爲wrap_content –

+0

android:layout_alignBottom =「true」android:layout_alignParentBottom =「true」 – mukesh

回答

0


遵循以下步驟:

  1. 添加ID到最頂層的相對佈局說:機器人:ID = 「@ + id/rtvlt_first」
  2. 在第二個RelativeLayout中刪除alignparenttop屬性。
  3. 添加機器人:tobottomof = 「@ ID/rtvlt_first」 ...

    試試這個....
    祝您好運!
+0

tobottomof無法識別:/ –

1

更好的是將LinearLayout與垂直方向一起作爲Parent的兩個孩子RelativeLayouts。如果您可以將RelativeLayouts的高度權重設置爲80:20,那麼它將適合整個屏幕。

+0

如果沒有其他答案會出現,我會考慮這一點。 –

1
<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

<RelativeLayout 
     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" > 
      <RelativeLayout 
      android:id="@+id/maps_manager_menu" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" > 

      <!-- Top --> 
      <Button 
       android:id="@+id/maps_manager_top_left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/empty" /> 

      <Button 
       android:id="@+id/maps_manager_top_middle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_top_left" 
       android:contentDescription="@string/empty" /> 

      <Button 
       android:id="@+id/maps_manager_top_right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_top_middle" 
       android:contentDescription="@string/empty" /> 

      <!-- Middle --> 
      <Button 
       android:id="@+id/maps_manager_middle_left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/maps_manager_top_left" 
       android:contentDescription="@string/empty" /> 

      <Button 
       android:id="@+id/maps_manager_middle_middle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_middle_left" 
       android:layout_below="@id/maps_manager_top_middle" 
       android:contentDescription="@string/empty" /> 

      <Button 
       android:id="@+id/maps_manager_middle_right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_middle_middle" 
       android:layout_below="@id/maps_manager_top_right" 
       android:contentDescription="@string/empty" /> 

      <!-- Bottom --> 
      <Button 
       android:id="@+id/maps_manager_bottom_left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/maps_manager_middle_left" 
       android:contentDescription="@string/empty" /> 

      <Button 
       android:id="@+id/maps_manager_bottom_middle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_bottom_left" 
       android:layout_below="@id/maps_manager_middle_middle" 
       android:contentDescription="@string/empty" /> 

      <Button 
       android:id="@+id/maps_manager_bottom_right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_bottom_middle" 
       android:layout_below="@id/maps_manager_middle_right" 
       android:contentDescription="@string/empty" /> 

     </RelativeLayout> 

     <RelativeLayout 
       android:id="@+id/maps_manager_controls" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignBottom="true" 
       android:layout_below="@id/maps_manager_menu" > 

       <ToggleButton 
        android:id="@+id/maps_manager_help" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

      </RelativeLayout> 
    </RelativeLayout> 
</ScrollView> 
+0

ScrollView只能有一個孩子:/ –

+0

您可以使用scrollview作爲根標籤並設置其佈局參數以包裝內容 –

1
<ScrollView 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" > 

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <RelativeLayout 
      android:id="@+id/maps_manager_menu" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" > 

      <!-- Top --> 
      <Button 
       android:id="@+id/maps_manager_top_left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/hello_world" /> 

      <Button 
       android:id="@+id/maps_manager_top_middle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_top_left" 
       android:contentDescription="@string/hello_world" /> 

      <Button 
       android:id="@+id/maps_manager_top_right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_top_middle" 
       android:contentDescription="@string/hello_world" /> 

      <!-- Middle --> 
      <Button 
       android:id="@+id/maps_manager_middle_left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/maps_manager_top_left" 
       android:contentDescription="@string/hello_world" /> 

      <Button 
       android:id="@+id/maps_manager_middle_middle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_middle_left" 
       android:layout_below="@id/maps_manager_top_middle" 
       android:contentDescription="@string/hello_world" /> 

      <Button 
       android:id="@+id/maps_manager_middle_right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_middle_middle" 
       android:layout_below="@id/maps_manager_top_right" 
       android:contentDescription="@string/hello_world" /> 

      <!-- Bottom --> 
      <Button 
       android:id="@+id/maps_manager_bottom_left" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/maps_manager_middle_left" 
       android:contentDescription="@string/hello_world" /> 

      <Button 
       android:id="@+id/maps_manager_bottom_middle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_bottom_left" 
       android:layout_below="@id/maps_manager_middle_middle" 
       android:contentDescription="@string/hello_world" /> 

      <Button 
       android:id="@+id/maps_manager_bottom_right" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toRightOf="@id/maps_manager_bottom_middle" 
       android:layout_below="@id/maps_manager_middle_right" 
       android:contentDescription="@string/hello_world" /> 

     </RelativeLayout> 

     <RelativeLayout 
       android:id="@+id/maps_manager_controls" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/maps_manager_menu" > 

       <ToggleButton 
        android:id="@+id/maps_manager_help" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

      </RelativeLayout> 
    </RelativeLayout> 
</ScrollView> 
+0

現在我幾乎看到兩個親戚,但他們每個人的尺寸都等於屏幕尺寸。那很糟。 –

+0

已修改,請重試 –

相關問題