繁体   English   中英

将按钮对准屏幕右下方?

[英]Align a button to the bottom right of screen?

我在“操作”按钮的右侧有一个提交按钮:

提交按钮

我试过使用代码:

android:gravity="bottom|right"

但它不起作用,并且仍然停留在同一位置。

我的完整代码是这样的:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="bottom"
    android:keepScreenOn="true"
    android:textSize="25dp"
    android:padding="30dp"
    android:textStyle="bold"
    android:textAlignment="center"
    android:text="@string/select_action"
    android:id="@+id/btnSelectPhoto"
    android:layout_alignParentBottom="true"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/btnSelectPhoto"
    android:keepScreenOn="true"
    android:gravity="bottom|right"
    android:padding="30dp"
    android:text="@string/submit"
    android:textSize="25dp"
    android:textStyle="bold"
    android:id="@+id/btnSubmit"
    android:layout_alignParentBottom="true"
    />

即使使用上面的代码,布局仍然与图像相同。 我怎样才能解决这个问题?

修复:由于Egor N,添加了android:layout_alignParentRight =“ true”。

android:layout_alignParentRight="true"应该可以完成这项工作。 但是,您应该摆脱android:layout_toRightOf="@id/btnSelectPhoto"

android:gravity不起作用,因为此值应用于视图内的内容(按钮内的文本)。

您可以在两个波顿之间使用simlpe视图

例如:

<LinearLayout
    android:orientation="horizontal"
    android:weightSum="3"
    android:layout_width="match_parent"
    android:layout_height="80dp"
>
    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM