带有自定义按钮的Android布局

带有自定义按钮的Android布局,android,android-layout,Android,Android Layout,我试图让按钮在屏幕的中心和底部的注销按钮。我有垂直居中的按钮,但它不会水平居中 我做错了什么 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_height="match_parent"

我试图让按钮在屏幕的中心和底部的注销按钮。我有垂直居中的按钮,但它不会水平居中

我做错了什么

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:padding="10dp"
    android:weightSum="1">

<TextView
    android:layout_width="match_parent"
    android:textColor="#000000"
    android:id="@+id/etEmailLabel"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:gravity="center"
    android:textAlignment="center" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:layout_marginBottom="20dp"
    android:weightSum="1"
    android:layout_weight="0.98">

    <Button
        android:layout_width="291dp"
        android:layout_height="273dp"
        android:id="@+id/DataLog"
        android:background="@layout/mybutton"
        android:text="Log Location"
        android:layout_gravity="center" />

</LinearLayout>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/bLogout"
    android:text="Logout"/>

</LinearLayout>
自定义按钮代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="50dp"
    android:layout_width="50dp"
    android:layout_gravity="center"
    android:shape="oval">
    <solid android:color="#FFFFFF"/>
    <stroke android:width="2sp" android:color="#fff" />
</shape>

我不明白为什么LinearLayout高度小于按钮,但可以通过对父视图组应用重力使其居中:


此外,线性布局上的权重和权重总和也不会有任何影响。

尝试使用相对布局兴趣,这会删除所有居中。因为首先使用线性布局,现在可以在需要显示的位置拖放按钮,所以多亏了您,我才算出来。我必须把主要的线性布局居中。不完全确定为什么会这样,但仍然很有趣。非常感谢。NP,布局的其余部分有很多没有意义的东西-我建议您了解更多有关视图组的信息。
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:layout_marginBottom="20dp"
    android:weightSum="1"
    android:gravity="center"
    android:layout_weight="0.98">

    <Button
        android:layout_width="291dp"
        android:layout_height="273dp"
        android:id="@+id/DataLog"
        android:background="@layout/mybutton"
        android:text="Log Location" />

</LinearLayout>