【问题标题】:TextView is gone and Button is visibleTextView 不见了,Button 可见
【发布时间】:2019-04-25 12:14:36
【问题描述】:

Textview 项目不可见。他们下面的Button是。

尝试将LinearLayout 更改为RelativeLayout,将match_parent 和内容更改为0dp。他们都没有工作。只有按钮显示在正确的位置,好像 TextView 在那里但不可见。这些视图在 Activity 的onCreate() 中调用。

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".EnterData">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tvDateIn"
        android:layout_marginStart="15dp"
        android:layout_marginTop="15dp"
        tools:text="Date"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:id="@+id/tvDescIn"
        android:layout_marginTop="15dp"
        android:layout_marginStart="15dp"
        tools:text="Description"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:id="@+id/tvAmountIn"
        tools:text="California"
        android:layout_marginTop="15dp"
        android:layout_marginStart="15dp"
        android:textColor="#000"
        android:textSize="17sp"/>
    <Button
        android:id="@+id/btnSendData"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:text="Send Data"/>


</LinearLayout>

【问题讨论】:

  • 请附上一张截图。
  • 您是否尝试在 TextViews 中将“tools:text”替换为“android:text”?
  • android:text 改变 tools:text

标签: android android-layout textview


【解决方案1】:

您尝试使用android:text 而不是tools:texttools:text仅在 Android Studio 中可见。

如果您使用的是tools:text,则应该使用yourTextView.setText("yourText")

【讨论】:

    【解决方案2】:

    在 xml 中使用 android:text="abc" 而不是在 textView 中使用 tool:text。 由于 tool:text 用于 android studio 布局预览。运行应用程序时它不显示文本。 而 android:text 用于将文本设置为 textview、button 等。

    【讨论】:

      【解决方案3】:

      是的,一切正常,只需放置 android:text 即可。 非常感谢。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-06
        • 1970-01-01
        • 1970-01-01
        • 2016-04-11
        • 2020-12-30
        • 1970-01-01
        • 1970-01-01
        • 2012-12-06
        相关资源
        最近更新 更多