gpt4 book ai didi

android - 如何在RelativeLayout中水平居中按钮?

转载 作者:行者123 更新时间:2023-12-05 00:21:31 25 4
gpt4 key购买 nike

首先搜索解决方案(例如 here )后,我找到了以下解决方案:

android:layout_centerHorizontal="true"

这对我不起作用(见第三个按钮)。以下是 RelativeLayout 中三个按钮的完整示例代码,其中中间的按钮应该居中(水平和垂直,按钮所在的位置),另外两个按钮应该对称放置在屏幕上,水平居中。但是,它们不是,使用我多次找到的建议解决方案。

那么我想念什么?

完整代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/checkscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.impyiablue.checkpoint.CheckScreen">

<RelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:orientation="vertical">


<Button
android:id="@+id/check_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check_next"
android:textSize="20sp"
android:padding="25dip"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/check_now"
android:layout_alignStart="@+id/check_now"
android:layout_marginTop="50dp" />

<Button
android:id="@+id/check_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/check_now"
android:padding="70dip"
android:textSize="20sp" />

<Button
android:id="@+id/check_redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/check_redo"
android:textSize="20sp"
android:padding="25dip"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/check_now"
android:layout_alignStart="@+id/check_now"
android:layout_marginBottom="50dp" />

</RelativeLayout>


</LinearLayout>

Screenshot

最佳答案

`

<Button
android:id="@+id/check_redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/check_redo"
android:textSize="20sp"
android:padding="25dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp" />

`
您可以尝试使用 RelativeLayout 作为您的根布局,这将使事情更容易管理。

关于android - 如何在RelativeLayout中水平居中按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46752662/

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