简体   繁体   English

Android Studio布局编辑器

[英]Android Studio Layout Editor

Hey i just started using the Android Studio Layout Editor, so i just made a new projcect with basic activity, so it jsut has a hello world text in the middle. 嘿,我刚刚开始使用Android Studio布局编辑器,因此我刚刚进行了一个具有基本活动的新项目,因此jsut中间有一个hello world文本。 I followed all the instructions from: https://developer.android.com/training/basics/firstapp/building-ui But mine looks nothing like that, mine is just a blue rectangle with nothing on it. 我遵循了以下所有说明: https : //developer.android.com/training/basics/firstapp/building-ui但是我的看上去并不像那样,我只是一个蓝色矩形,上面没有任何东西。 I noticed some errors in the Warning and Errors message tab: 我在警告和错误消息选项卡中注意到一些错误:

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

I have no idea why this is happening since i very recently installed Android Studio and was not expecting any errors with a brand new basic project. 我不知道为什么会这样,因为我最近安装了Android Studio,并且没想到全新基础项目会出现任何错误。 Hope you can help, thanks! 希望能对您有所帮助,谢谢!

EDIT: THE XML TEXT AFTER I DELETED THE HELLO WORLD AND SIMPLE DRAGGED AND DOPPED AN EDIT TEXT 编辑:我删除HELLO WORLD并简单拖动并添加了编辑文本后的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>

ANOTHER EDIT: When hovering over the EditText (becouse it is red underlined) it says This view is not constrained. 另一个编辑:将鼠标悬停在EditText上时(因为它带有红色下划线),它表示此视图不受约束。

You're using a constraint layout but your text view is using absolute position. 您使用的是约束布局,但文本视图使用的是绝对位置。 tools:layout_editor_absoluteX="126dp" & tools:layout_editor_absoluteY="158dp" . tools:layout_editor_absoluteX="126dp"tools:layout_editor_absoluteY="158dp"

https://developer.android.com/training/constraint-layout/ 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" />

Also, your app theme is looking for coordinatorLayout. 另外,您的应用程序主题正在寻找coordinatorLayout。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM