我试图让按钮位于屏幕中心和底部的注销按钮。我有垂直居中的按钮,但它不会水平居中。带有自定义按钮的Android布局
我做错了什么?
<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>
尝试使用相对布局 – HassanUsman
有趣的是,删除了所有居中。 – Walorn
因为首先你使用线性布局现在拖放按钮在你想要的地方 – HassanUsman