你可以在RelativeLayout中将按钮居中吗? [英] Can you center a Button in RelativeLayout?

查看:13
本文介绍了你可以在RelativeLayout中将按钮居中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在相对布局中将按钮居中,这可能吗?我试过重力和方向功能,但它们什么也没做.

I'm trying to center a button in relative layout, is this possible? I've tried the Gravity and Orientation functions but they don't do anything.

推荐答案

尝试

android:layout_centerHorizontal="true"

正是这样,它对我有用:

Exactly like this, it works for me:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#ff0000">

    <Button
        android:id="@+id/btn_mybutton"
        android:layout_height="wrap_content"
        android:layout_width="124dip"
        android:layout_marginTop="5dip"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

这篇关于你可以在RelativeLayout中将按钮居中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆