2015-03-31 38 views
0

我想獲得一個相對佈局來環繞一個按鈕。它看起來像這樣:如何獲得相對佈局高度以環繞按鈕?

<RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      style="@style/Theme.MyCompany.Button.Container" 
      android:layout_weight="10"> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_gravity="center" 
       style="@style/Theme.MyCompany.Button.MyList" 
       android:id="@+id/this is my button" 
       android:text="@string/this_is_my_button"/> 

     </RelativeLayout> 

它在寬度方面很好,但高度達到上述LinearLayout。

我試圖通過創建一個白色按鈕主題來破解它,但它只是創建一個更輕的視圖。

我該如何讓這個按鈕出現在頁面的底部,有沒有容器的好處?

+0

這個傳說中的「LinearLayout」在哪裏? – tachyonflux 2015-03-31 02:00:54

回答

0

如果我理解你的問題正確,您的東東到這條線android:layout_alignParentBottom="true"移動到相對佈局

因此,像這樣:

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     style="@style/Theme.MyCompany.Button.Container" 
     android:layout_alignParentBottom="true" 
     android:layout_weight="10"> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      style="@style/Theme.MyCompany.Button.MyList" 
      android:id="@+id/this is my button" 
      android:text="@string/this_is_my_button"/> 

    </RelativeLayout> 
0

嘗試了這一點只需更新相對佈局的「機器人:layout_height」 -

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     style="@style/Theme.MyCompany.Button.Container" 
     android:layout_weight="10"> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_gravity="center" 
      style="@style/Theme.MyCompany.Button.MyList" 
      android:id="@+id/this is my button" 
      android:text="@string/this_is_my_button"/> 

    </RelativeLayout> 
0

一些變化你的代碼,試試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout //this will wrap your button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_weight="10" > 

     <Button 
      android:id="@+id/this is my button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="this_is_my_button" /> 
    </RelativeLayout> 

</RelativeLayout> 
相關問題