android - 无法正确约束文本

标签 android android-studio android-layout

我不确定如何进行限制以使我的文本不会被顶部的应用栏隐藏。 enter image description here

我试过让约束有不同的 anchor ,但我不确定如何让它不被隐藏。

<TextView
    android:id="@+id/textintro"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Droid Desserts"
    android:textSize="24sp"
    android:textStyle="bold"
    tools:layout_editor_absoluteX="126dp"
    tools:layout_editor_absoluteY="322dp" />

最佳答案

您的 View 不受任何限制,因此它会跳转到 (0,0),因为错误是这样说的:

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints

请注意,tools 属性(见下文)只会影响您的预览,不会影响运行时间:

  • 首先删除这些属性:

    tools:layout_editor_absoluteX="126dp"
    tools:layout_editor_absoluteY="322dp"

    正是这些属性让您在工具栏后面看到了您的 View

  • 现在,一旦您可以在运行时看到您的 View ,您就可以为它们提供您想要的约束。

例如,如果您想将 View 居中放置在屏幕中间,您可以这样操作

 <TextView
    android:id="@+id/textintro"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Droid Desserts"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

关于android - 无法正确约束文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57885255/

相关文章:

java - 使用rxjava订阅时如何返回 boolean 值

android - 一个 fragment 的 Activity 有什么意义吗?

android - FocusChangeListener 不工作

java - 我希望外部链接在我的浏览器中打开

Android Studio 使我的测试模块依赖于应用程序模块

java - Android 最高效的列表容器

Android:一个人可以别名布局吗?

android - 比较使用 LocalBroadcastManager 和 Otto 的性能

android - 华为AdsKit AdListener.onAdFailed errorCode 2是什么意思?

java - 删除文件安卓