【问题标题】:One of the Text views is not visible文本视图之一不可见
【发布时间】:2021-04-22 15:56:40
【问题描述】:

我有这个 XML,在 Android Studio 中,TextView tv_question_title 看起来不错,但是当我运行应用程序时,文本是不可见的。运行应用程序时 XML 的其余部分看起来不错,下面的 TextView 看起来也不错。我在这里错过了什么?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layoutDirection="ltr"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#B2333333"
>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:id="@+id/white_part"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHeight_percent="0.75"
    android:background="@color/white"
    >

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
    android:id="@+id/tv_question_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:textColor="#333333"
    android:fontFamily="@font/molde_regular_webfont"
    tools:text="Thanks for feedback"
    android:gravity="center"
    app:layout_constraintTop_toTopOf="@id/white_part"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_marginStart="24dp"
    android:layout_marginEnd="24dp"
    android:layout_marginTop="35dp"
    />


<TextView
    android:id="@+id/tv_question_subtitle"
    android:fontFamily="@font/molde_regular_webfont"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    android:text="What can we do"
    android:layout_marginEnd="24dp"
    android:layout_marginStart="24dp"
    android:textColor="#333333"
    android:gravity="center"
    android:textSize="24sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tv_question_title"
    />

<EditText
    android:id="@+id/input_improve_offer"
    android:gravity="top"
    android:layout_width="0dp"
    android:layout_height="105dp"
    android:layout_marginStart="24dp"
    android:layout_marginEnd="24dp"
    android:layout_marginTop="22dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tv_question_subtitle"
    android:background="@drawable/border_improve_offer"

    />


<TextView
    android:id="@+id/tv_error"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="Error"
    android:layout_marginStart="10dp"
    app:layout_goneMarginStart="24dp"
    android:visibility="gone"
    android:textColor="@color/red_design"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="@+id/tv_question_title"
    app:layout_constraintStart_toEndOf="@+id/iv_caffeine_info"
    app:layout_constraintTop_toBottomOf="@+id/tv_question_subtitle"
    />



<com.google.android.material.button.MaterialButton
    android:id="@+id/btn_next"
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:minWidth="100dp"
    android:textSize="20sp"
    android:textColor="@color/white"
    android:fontFamily="@font/molde_regular_webfont"
    android:text="Next"
    android:textAllCaps="false"
    android:backgroundTint="@color/blue"
    app:cornerRadius="25dp"
    android:layout_marginTop="15dp"
    app:layout_constraintTop_toBottomOf="@id/input_improve_offer"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"

    />


</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 对不起,重复的文字,它不会让我在没有更多文字的情况下发布问题:(

标签: android xml android-layout


【解决方案1】:

您需要将tools 命名空间替换为android 命名空间。

tools 命名空间用于设计目的,只会在 Android Studio 设计预览中显示,而不是在您运行应用时显示。

所以替换这个:

tools:text="Thanks for feedback"

android:text="Thanks for feedback"

您可以从this documentation link 了解有关tools 命名空间的更多信息。

【讨论】:

  • @Akiva 很高兴听到......如果这有帮助,请接受答案
猜你喜欢
  • 2015-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多