gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:10:32 24 4
gpt4 key购买 nike

我是 android 中布局结构的新手,我的任务是构建一个底部有一个按钮(也居中水平)的 Activity ,按钮底部和底部之间有一点填充可见屏幕。

挑战在于如何在相对布局中做到这一点,并使它无论屏幕尺寸如何都锚定到同一位置

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

最佳答案

dev docs有一些示例布局和 API Demos项目也很棒。

下面的布局会将按钮放在底部,但请记住,当您向相对布局添加更多控件时,它们必须相互尊重。像 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>

关于android - 如何将按钮锚定在android中相对布局的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6285320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com