2015-03-31 82 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> 
相关问题