简体   繁体   English

将按钮对准屏幕右下方?

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

I have a submit button here on the right of "Action" Button: 我在“操作”按钮的右侧有一个提交按钮:

提交按钮

I've tried to use the code: 我试过使用代码:

android:gravity="bottom|right"

but it doesn't work, and it still stays on the same place. 但它不起作用,并且仍然停留在同一位置。

My full code is this: 我的完整代码是这样的:

<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"
    />

Even with the code above, the layout is still the same as the image. 即使使用上面的代码,布局仍然与图像相同。 How can I fix this? 我怎样才能解决这个问题?

Fixed: Added android:layout_alignParentRight="true", Thanks to Egor N. 修复:由于Egor N,添加了android:layout_alignParentRight =“ true”。

android:layout_alignParentRight="true" should do the job. android:layout_alignParentRight="true"应该可以完成这项工作。 But, you should get rid of android:layout_toRightOf="@id/btnSelectPhoto" . 但是,您应该摆脱android:layout_toRightOf="@id/btnSelectPhoto"

android:gravity didn't work, because this value is applied to content inside the view (text inside a button). android:gravity不起作用,因为此值应用于视图内的内容(按钮内的文本)。

You can use a simlpe View between the two bottons 您可以在两个波顿之间使用simlpe视图

for example: 例如:

<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