【发布时间】:2023-03-08 22:41:01
【问题描述】:
如果我正在使用:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="1.0"
android:background="@drawable/mainpgbg">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="0.50"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_gravity="center_horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Log In"
android:textSize="24sp"
android:id="@+id/logInBtn"
android:layout_gravity="center_vertical"
android:layout_weight="0.50"
android:background="@drawable/round"
android:padding="20dp"
android:layout_marginBottom="128dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
我预计RelativeLayout 将显示在屏幕的中心,但似乎您需要RelativeLayout 来居中元素,但是您需要LinearLayout 来创建相对大小的元素。
我怎样才能做到这两点?将相对大小的元素居中?
【问题讨论】:
标签: android element center android-relativelayout