如何将按钮锚定在android中相对布局的底部

发布于 2024-11-14 07:25:08 字数 152 浏览 6 评论 0原文

我对android中的布局结构很陌生,我的任务是构建一个活动,该活动在底部有一个按钮(水平居中),在按钮底部和可见底部之间有一点填充屏幕。

挑战是如何在相对布局中做到这一点,并使其锚定在同一个位置,无论屏幕大小如何。

如果有人能指出我正确的方向,那就太好了!

I'm new to the layout structure in android and I'm tasked with building an activity that has a button at the bottom (centered horiz as well) with a small bit of padding between the bottom of the button and the bottom of the visible screen.

The challenge is how to do this in relative layout and make it anchor to the same spot regardless of screen size

If anyone can point me in the right direction that would be great!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一页 2024-11-21 07:25:08

开发文档有一些示例布局,API 演示项目也很棒。

下面的布局会将按钮放在底部,但请记住,当您向相对布局添加更多控件时,它们必须相互尊重。像layout_above这个按钮或者把这个按钮放在最后并确保它有一个像android:layout_below =“id_of_other_bottommost_controll”的属性

<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent" 
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:text="button"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

The dev docs have some sample layouts and the API Demos project is great too.

The layout below will put the button at the bottom, but remember as you add more controls to a relative layout they will have to respect each other. like layout_above this button or put this button at the end and make sure it has an attribute like android:layout_below="id_of_other_bottommost_controll"

<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent" 
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:text="button"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>
扛刀软妹 2024-11-21 07:25:08

您应该能够在按钮属性的杂项部分中执行此操作。查找“布局对齐父底部”和“布局中心水平”。该按钮必须位于填充整个屏幕的相对布局内,此方法才能起作用。

You should be able to do this in the misc section of the button properties. Look for "Layout align parent bottom" and "Layout center horizontal". The button must be inside a relative layout that fills the entire screen for this method to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文