gpt4 book ai didi

java - 在relativelayout中使用layout_toLeftOf布局的按钮不显示

转载 作者:行者123 更新时间:2023-12-02 00:51:58 25 4
gpt4 key购买 nike

我正在尝试将一个按钮布局在屏幕居中的 TextView 的左侧。我的布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="foo"
android:id="@+id/center"
/>

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left button"
android:layout_toLeftOf="@id/center" />
</RelativeLayout>

不幸的是,该按钮没有出现。我得到以下结果:alt text

如您所见,该按钮没有显示。如果我使用layout_toRightOf,那么按钮就会出现在 TextView 的右侧,正如预期的那样。

知道我在这里做错了什么吗?

最佳答案

  1. 您尚未提供任何用于定位 TextView 的规则。如果您希望 TextView 居中,请这么说(例如 android:layout_centerInParent="true")
  2. 您尚未提供任何垂直定位 Button 的规则。
  3. 使用 hierarchyviewer 检查您的布局,以确定事物的放置位置。

关于java - 在relativelayout中使用layout_toLeftOf布局的按钮不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2629691/

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