无法在 Android Studio 中向 activity_main.xml 添加任何项目

Can't add any items to activity_main.xml in Android Studio

在 Android Studio 中,我无法在设计视图中将调色板中的任何项目添加到 activity_main.xml。它只是不允许我拖放它们。知道为什么会这样吗?

这是打印屏幕:

根据 android studio 中用于 android 开发的新设计方法,您不能向 activity_main.xml 添加任何元素。相反,您应该将它们添加到 content_main.xml.

您可以从 回答中了解更多信息。

你可以阻止它发生。
回答者BNK

If you create a new project, you can choose Empty Activity template instead of Blank Activity. If you create a new activity, you can choose Empty Activity instead of Blank Activity too.

如何使用片段创建空 Activity?

You start by creating an activity using the "Empty Activity" template. Then, add a fragment class yourself or possibly via New > Fragment. Please understand that all of the "New >" options, for activities, fragments, etc., are all driven by templates. Those templates do what they do. If you do not want what they are generating, don't use them, and add the classes, resources, manifest entries, and such yourself. Personally, I almost never use those templates, because it's simpler IMHO just to create it all yourself than to rip out all the stuff you don't need that gets generated.

我有同样的问题。在设计页面中,我看到错误消息 "Render Error..." 我点击 Android Studio->检查更新->更新并重启 android studio 更新后,从 Palette 拖放到设计页面的功能有效。

Check ConstraintLayout properties:
layout width and layout height should be "match parent", not "wrap content". 

对我有用。

当你标记了一个 witget 编辑器不让你拖动。