【问题标题】:Android Studio does not show components on design view, but shows on emulator, any idea why? [duplicate]Android Studio 不在设计视图上显示组件,而是在模拟器上显示,知道为什么吗? [复制]
【发布时间】:2019-02-01 02:52:32
【问题描述】:

我刚开始使用来自 android.com 的 Build your first app 教程,但由于某种原因,设计视图没有显示我拖放到其中的任何内容。我尝试创建按钮、文本、纯文本等,都没有错误,但是,我只能在运行应用程序时看到它。 我错过了什么?

在 Ubuntu 18.04.1 LTS 上运行 Android Studio 3.1.4。

这是我第一次使用它,我在发布之前搜索了类似的问题,只发现与我的问题不够相似的问题/答案没有帮助。我尝试重建缓存/重新启动并使缓存无效,但无济于事。

这里有一些快照:

工作室快照

模拟器截图

最后是activity_main.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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginStart="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:text="@string/title_home"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="KoDy Abbott"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

如果您需要其他任何东西来帮助回答我的问题,请告诉我。提前谢谢你,希望我忽略了一些简单的事情,但此时我更容易问,然后再敲几个小时......

【问题讨论】:

  • 默认主题会导致这个问题,我个人认为它对新开发者非常不友好!
  • 尝试在设计部分更改api级别或主题。

标签: android xml android-layout android-studio


【解决方案1】:

您的项目没有错误,但最近更新的支持库中存在一些错误

将支持库版本更改为 28.0.0-alpha1 即可正常使用

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'

【讨论】:

  • 我能够更改主题,并且成功了。
【解决方案2】:

其他解决方案是您可以在左上角找到一个图像按钮。单击它,您可以找到一个名为“强制刷新布局”的选项,单击它,您的问题将得到解决。

【讨论】:

  • 试过了,没有运气。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-07
  • 2018-08-17
相关资源
最近更新 更多