Android Studio布局编辑器

时间:2018-06-27 12:38:40

标签: android android-studio

嘿,我刚刚开始使用Android Studio布局编辑器,所以我刚刚制作了一个带有基本活动的新项目,所以它中间有一个hello world文本。我遵循了以下所有指示: https://developer.android.com/training/basics/firstapp/building-ui 但是我的看起来并不像那样,我只是一个蓝色的矩形,上面没有任何东西。 我在“警告和错误”消息选项卡中发现了一些错误:

1 Rendering Error
Failed to find style 'coordinatorLayoutStyle' in current theme   Tip: Try to refresh the layout. 
1 Using Private resources: 
The resource @string/appbar_scrolling_view_behavior is marked as private in com.android.support:design  Private resources should not be referenced; the may not be present everywhere, and even where they are they may disappear without notice.  To fix this, copy the resource into your own project instead.
1 Missing Styles:
Missing styles. Is the correct theme chosen for this layout?  Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
1 Failed to instance one or more classes
The following classes could not be instantiated:
- android.support.design.widget.CoordinatorLayout (Open Class, Show Exception, Clear Cache)
- android.support.design.widget.AppBarLayout (Open Class, Show Exception, Clear Cache)
 Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.  If this is an unexpected error you can also try to build the project, then manually refresh the layout.  Exception Details java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener Copy stack to clipboard

我不知道为什么会这样,因为我最近安装了Android Studio,并且没想到全新的基础项目会出现任何错误。希望您能提供帮助,谢谢!

编辑: 在删除HELLO世界之后,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">

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="Name"
        tools:layout_editor_absoluteX="126dp"
        tools:layout_editor_absoluteY="158dp" />
</android.support.constraint.ConstraintLayout>

另一个编辑:将鼠标悬停在EditText上时(因为它带有红色下划线),它表示此视图不受限制。

1 个答案:

答案 0 :(得分:1)

您使用的是约束布局,但文本视图使用的是绝对位置。 tools:layout_editor_absoluteX="126dp"tools:layout_editor_absoluteY="158dp"

https://developer.android.com/training/constraint-layout/

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

此外,您的应用主题正在寻找coordinatorLayout。

<style name="AppTheme.NoActionBar">
  <item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>
</style>