Android Studio 布局编辑器无法呈现自定义视图 [英] Android Studio layout editor cannot render custom views

查看:46
本文介绍了Android Studio 布局编辑器无法呈现自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android Studio 中,布局编辑器无法预览 xml 中的自定义视图.

In Android Studio, the layout editor cannot preview custom views in xml.

非常简单的例子:

public class MyCustomView extends FrameLayout {
    public MyCustomView(Context context) {
        super(context);
    }

    public MyCustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
}

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <com.myprojectxxx.view.MyCustomView
        android:layout_width="48dp"
        android:layout_height="48dp" />

</LinearLayout>

Android Studio 总是说,

Android Studio always says,

渲染问题

找不到以下类:

  • com.myprojectxxx.view.MyCustomView(修复构建路径,创建类)

提示:尝试构建项目

当然,我有这门课.如果我点击创建类",它会抱怨同一个类已经存在.如果我重建那个项目,什么都不会改变.

Of course, I HAVE that class. If I click "Create Class", it complains that the same class already exists. If I rebuild that project, nothing changes.

而且,是的,该项目在我的 Android 设备上运行良好.此外,它在 Eclipse ADT 中呈现得非常好.但是,在 Android Studio 中,它总是说找不到类."

And, yes, the project works very well on my Android device. Also, it is rendered very well in Eclipse ADT. However, in Android Studio, it always says that "CLASSES COULD NOT BE FOUND."

Android Studio 无法预览带有自定义视图的 xml 文件?这有什么问题吗?

Android Studio does not have the ability to preview a xml file with custom views? What's wrong with this?

推荐答案

IDEA 也支持并正确显示自定义视图组件,但由于 IntelliJ IDEA 使用输出目录中的类文件来呈现此类组件,因此您必须进行构建->首先在你的项目上制作项目.

Custom view components are also supported and shown correctly in IDEA, But since IntelliJ IDEA uses class files from your output directory to render such components, you have to do build->make project on your project first.

参考

这篇关于Android Studio 布局编辑器无法呈现自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆