【问题标题】:Views get stuck on Top Left Corner (Android Studio)视图卡在左上角(Android Studio)
【发布时间】:2018-12-18 09:38:39
【问题描述】:

我是 Android 开发的初学者,所以我决定下载 Android Studio。
我创建了一个项目,在尝试构建应用程序的前几次尝试编译器给出了一个错误,因为我丢失了一些文件,所以我安装了它们。

我的问题是,当它最终完成构建应用程序时,即使显示它存在于组件树中,我也看不到 Hello Word 文本视图,我添加了另一个文本视图并我一松开鼠标按钮它就消失了。这也发生在我尝试使用的所有其他组件上,按钮、图像、视图等等。

我还注意到,通过单击左上角组件树上的一个组件,将显示 2 个按钮:一个带有 imo 表示它应该从布局中删除组件的符号,另一个带有“ ab" 我不知道是什么意思。这表明我应该出于某种原因将组件卡在那里。

感谢您的关注,

若昂·奥利维拉

PS:

链接
Components seem to be stuck in the Top Left Corner
Text View is not visible

activity_mail.xml 中的 XML 文本

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout 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="match_parent"
tools:context=".MainActivity">

<TextView
    android:id="@+id/sample_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />
    </android.support.constraint.ConstraintLayout>

【问题讨论】:

  • 您忘记添加约束布局的结束标记
  • 看看是否有效
  • @Opriday 它已关闭但不在该行,在 tools:context=".MainActivity" 之后有一个右括号。除了设计视图之外,我没有弄乱任何视图。你知道会发生什么吗?
  • 您的目标是哪个 SDK 和支持版本?我注意到使用 28.0.0-alpha3 会在预览中出现错误,尽管应用程序按预期构建和运行。尝试将 SDK 更改为 27 并支持到 27.0.0。
  • android-26 表示,转到 skd 管理器,Sdk 平台然后检查 API 级别 26 平台是否安装。如果未安装,则安装并同步 gradle 或重建项目。

标签: android android-studio build


【解决方案1】:

你的观点就在你约束它们的地方。尺寸为 1dp 的视图不可见,这是您的代码:

android:layout_width="1dp"
android:layout_height="1dp"

将视图设置为合适的大小,您就会看到它。

【讨论】:

  • 感谢您的回答,我应该将值更改为什么?
  • wrap_content 或足以显示视图的值
  • 我改变了它,但没有改变。检查我的帖子我更新了 xml 文件
  • 复制并粘贴您的 xml,不带前导空格和约束布局的结束标记。
  • 我修好了@mTak
【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/sample_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>

【讨论】:

  • 是的,这似乎是它应该的样子。我真的不知道问题出在哪里。
猜你喜欢
  • 1970-01-01
  • 2021-10-10
  • 2021-01-03
  • 2013-10-03
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 2017-01-18
相关资源
最近更新 更多