在 activity_main.xml 中看不到元素布局 android studio

新手上路,请多包涵

我从 android studio 开始,看不到元素(按钮、TextView、..)我拖放到 activity_main.xml 页面中的设计页面。这些元素存在于我的 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:layout_editor_absoluteY="25dp">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/title_home"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="1dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:menu="@menu/navigation" />

    <Button
        android:id="@+id/button"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:text="ClickMe"
        tools:layout_editor_absoluteX="-73dp"
        tools:layout_editor_absoluteY="29dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="20dp" />

</android.support.constraint.ConstraintLayout>

我的画布完全是空的。

编辑 :

我有 2 个错误:

  • 渲染问题: Failed to find style 'bottomNavigationStyle' in current theme Tip: Try to refresh the layout.

  • ConstraintLayout 中缺少约束: This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints

原文由 user9007028 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 499
2 个回答

您可以通过修复 styles.xml 文件来解决此问题。

找到 styles.xml

然后你只需要在这段代码中添加 Base :

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

最终代码:

 <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

原文由 Johira Afzali 发布,翻译遵循 CC BY-SA 4.0 许可协议

如果您遇到与此页面相同的错误,则应将 com.android.support:appcompat-v7:28.0.0-alpha3 更改为 com.android.support:appcompat-v7:28.0.0-alpha1 build.gradle(Module: app) 并单击 File -> Invalidate Caches.现在一切正常。

在此处输入图像描述

当然你需要上网才能下载 com.android.support:appcompat-v7:28.0.0-alpha1

原文由 Hossein Seifi 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题