机器人:相对布局两个按钮占据了所有可用的水平空间 [英] android: relative layout two buttons occupy all the available horizontal space

查看:123
本文介绍了机器人:相对布局两个按钮占据了所有可用的水平空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相对布局和我有这两个按钮分别文本你好和世界。我想这两个键可以位于彼此相邻的和相等占有可用整个水平空间。

i have a relative layout and i have two buttons in it with texts "hello" and "world" respectively. i want these two buttons to lie adjacent to each other and equally occupy the whole horizontal space available.

我试过以下,但没有得到预期的输出

i tried the following but didnt get expected output

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

     <Button android:layout_height="wrap_content" android:layout_width="wrap_content"      android:text="@string/world" android:id="@+id/world"
     android:layout_alignParentRight="true"
     android:layout_toRightOf="@+id/hello"
     android:layout_alignTop="@+id/hello"
  />  


       <Button
          android:id="@+id/hello"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello"
          android:layout_alignParentLeft="true"
          android:layout_alignParentBottom="true"
        />
   </RelativeLayout>

我试图改变Android的:layout_width两个孩子来FILL_PARENT,但没有工作过

i tried changing the android:layout_width of both children to fill_parent but that didnt work too.

我在使用的LinearLayout与layout_weight设置为两个孩子的0.5的工作解决方案,但我想知道是否有办法做到这一点相对布局本身。

i have a working solution of using LinearLayout with layout_weight set to 0.5 on both childs but i wanted to understand if there is way to do that in relative layout itself.

感谢

推荐答案

您无法使用 RelativeLayout的做到这一点。尝试的LinearLayout layout_weight 属性。

You can't do this with RelativeLayout. Try LinearLayout and the layout_weight attribute.

这篇关于机器人:相对布局两个按钮占据了所有可用的水平空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆