【问题标题】:Equal Button Widths In A View视图中的相等按钮宽度
【发布时间】:2011-05-07 08:21:47
【问题描述】:

我想知道,使用 RelativeLayout,您是否可以并排放置 2 个或三个按钮,并且它们的宽度在整个视图中是均匀设置的。例如如果屏幕为 300 像素,则按钮将自动采用 100 像素宽度(假设没有填充等)。

我不能真正提供代码...因为我不知道该怎么做=0)

【问题讨论】:

  • 看起来你有一个分身。 stackoverflow.com/questions/5917489
  • 是的,我无法访问我的帐户,也无法记住我之前使用的登录方法……然后我想起来了。我在 Stack 上进行了快速搜索,但我必须使用错误的关键字 =0\

标签: android android-relativelayout


【解决方案1】:

我会在你的相对布局中放置一个线性布局(假设你需要相对布局来做其他事情),方向水平并给每个按钮相同的权重。

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

<!--  Some stuff above -->
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" 
  android:orientation="horizontal"
   android:layout_width="fill_parent" android:layout_alignParentLeft="true">
           <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/btn"
            android:text="left" />
             <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btn1"
            android:layout_weight="1"
            android:text="center"/>
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btn2"
            android:layout_weight="1"
            android:text="right"/>

   </LinearLayout>
   <!--  Or below -->
</RelativeLayout>

【讨论】:

  • 有点恼火,因为我被称为新用户,所以八小时无法回答我自己的问题,但我已经破解了。和你说的差不多,但不完全一样。一旦堆栈允许我也将发布答案=0(
  • 使用此解决方案,您还需要将按钮宽度设置为 0dip。见stackoverflow.com/questions/5459168
  • 这就是我所拥有的。感谢您回答这个问题。我想我会把这篇文章留在这里以防万一其他人需要它=0)
猜你喜欢
  • 2016-12-07
  • 2012-12-15
  • 2012-12-21
  • 1970-01-01
  • 2022-11-03
  • 2015-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多