繁体   English   中英

Android Studio布局编辑器

[英]Android Studio Layout Editor

嘿,我刚刚开始使用Android Studio布局编辑器,因此我刚刚进行了一个具有基本活动的新项目,因此jsut中间有一个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 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>

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

您使用的是约束布局,但文本视图使用的是绝对位置。 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> 

暂无
暂无

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

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