gpt4 book ai didi

android:layout_centerHorizo​​ntal ="true"在 android 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 12:37:37 25 4
gpt4 key购买 nike

我正在使用此布局在中心制作图像和文本。但它不起作用。我只是在使用 android:layout_centerHorizo​​ntal="true"。为什么它不起作用我不明白。有人可以帮忙解决这个问题吗?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">


<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="@drawable/image_tutorial1" />

<TextView
android:textSize="14dp"
android:id="@+id/title"
android:layout_below="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/info4"
android:textColor="#000000"
android:textStyle="bold" />

</RelativeLayout>

最佳答案

在布局中,RelativeLayout 的宽度设置为wrap-content,它根本没有占据整个可用宽度。它的内容正在居中,但它们的父 View 正在缩小以适应它们。

为 root 尝试 fill_parent:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"

此外,带有 orientation="vertical"gravity="center_horizo​​ntal"LinearLayout 也可以更轻松地完成同样的工作。

关于android:layout_centerHorizo​​ntal ="true"在 android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15040916/

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