【问题标题】:My page doesn't want to show on the screen, but I can see it clearly in Android Studio preview我的页面不想在屏幕上显示,但我可以在 Android Studio 预览中清楚地看到它
【发布时间】:2021-05-09 10:56:20
【问题描述】:

我创建了一个应用程序项目,当我尝试单击将我引导至配置文件设置的配置文件时,它没有显示任何内容,但我在 xml 文件中放置了背景和一些文本。我在 logcat 中看到了这些错误:

E/BufferQueueProducer: [SurfaceTexture-0-26097-0](id:65f100000000,api:0,p:-1,c:26097) disconnect: not connected (req=1)
E/libprocessgroup: set_timerslack_ns write failed: Operation not permitted
E/ViewRootImpl@f0e9ae3[MainActivity]: Surface is not valid.

这是 xml 文件。具有 final_logo_transparent 的 ImageView 是我添加为背景的图像,并且我在其他 xml 文件中使用过它,因此与此无关。

<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    tools:context=".Profile">

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="409dp"
        android:layout_height="287dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="32dp"
        android:foregroundGravity="center"
        android:orientation="vertical"
        android:visibility="visible"
        app:layout_constraintBottom_toTopOf="@+id/textView2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/final_logo_transparent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:fontFamily="monospace"
        android:paddingHorizontal="80dp"
        android:text="Disconnect"
        android:textColor="#000000"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.98" />

    <ImageView
        android:id="@+id/profileImage"
        android:layout_width="221dp"
        android:layout_height="202dp"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="347dp"
        android:src="@drawable/user"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView5"
        app:layout_constraintVertical_bias="0.0" />


</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 请添加一些代码,以便我们做点什么。
  • 我已经添加了java文件
  • 你的问题是xml文件所以请添加xml文件
  • 抱歉,我已经添加了 XML 文件

标签: java xml android-studio


【解决方案1】:

首先,您在 XML 文件中的任何位置都没有 textview2 id,因此,在包含 final_logo_transparent 的 Imageview 中将其替换为 textview。 p>

适用于:

app:layout_constraintBottom_toTopOf="@+id/textView2"

收件人:

app:layout_constraintBottom_toTopOf="@+id/textView"

那么,

替换:

 app:srcCompat="@drawable/final_logo_transparent"

收件人:

 android:src="@drawable/final_logo_transparent"

如果不起作用,请尝试此解决方案,然后告诉我。

【讨论】:

  • 我仍然默认得到灰屏,而不是我在预览中看到的
  • 现在我尝试添加纯文本,但它并没有像必须的那样显示出来。我将 TextColor 和 TextColorHint 设置为黑色,我写了一些东西作为提示,但它不想显示
  • 你在使用任何api吗?
  • 我想我遇到了问题。所以我把 Java 类命名为 Profile,Android Studio 把它当做一个库,因为我看到 Android Studio 要我导入 Profile 类
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多