布局内容未显示

时间:2018-09-25 11:36:55

标签: android android-constraintlayout

  • 我正在使用Android Studio 3.1.4。
  • 虽然相对布局工作正常,但是每当我尝试使用浮动操作按钮创建新项目时,主布局的内容在预览窗口中都不可见。
  • 如果我选择默认的AppTheme,则什么也没有显示。
  • 在下面的图像中,我使用的是Material Dark主题,在大多数情况下,该主题解决了隐藏的小部件问题,但是当我尝试在fab上使用约束布局时,没有任何显示。
  • Gradle版本也没有问题。

任何帮助将不胜感激。

如给定图片所示,布局的内容未显示:

As seen in the given picture, the contents of the layout are not showing

我遇到的错误:

Errors which I am getting

布局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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".NoteActivity"
tools:showIn="@layout/activity_note">

<Spinner
    android:id="@+id/spinner_courses"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<EditText
    android:id="@+id/text_not_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:ems="10"
    android:hint="Note title"
    android:inputType="textMultiLine"
    app:layout_constraintEnd_toEndOf="@+id/spinner_courses"
    app:layout_constraintStart_toStartOf="@+id/spinner_courses"
    app:layout_constraintTop_toBottomOf="@+id/spinner_courses" />

<EditText
    android:id="@+id/text_note_text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:ems="10"
    android:hint="Note text"
    android:inputType="textMultiLine"
    app:layout_constraintEnd_toEndOf="@+id/text_not_title"
    app:layout_constraintHorizontal_bias="0.504"
    app:layout_constraintStart_toStartOf="@+id/text_not_title"
    app:layout_constraintTop_toBottomOf="@+id/text_not_title" />
</android.support.constraint.ConstraintLayout>

3 个答案:

答案 0 :(得分:1)

我找到了解决方案, 如下所示编辑build.gradle: 将compileSdkVersion从28更改为27,还将sdk的目标更改为27。 在依赖项中,也更改了以下内容: 实施'com.android.support:appcompat-v7:27.1.1' 实施'com.android.support:design:27.1.1'

现在一切正常。

答案 1 :(得分:1)

我通过在Gradle上添加以下软件包(并从28.0.0降级)来解决此问题;

implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:appcompat-v7:27.1.0'

这意味着也要更改目标并编译SDK版本。开发完成后,您可以稍后将其更改。 问候。

答案 2 :(得分:-1)

您所有子项的layout_width均为0dp。给它一个静态值或相应地使用wrap_content。