简体   繁体   中英

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

In Android Studio, I can't add any items from Palette to activity_main.xml in Design view. It just won't let me drag and drop them. Any idea why this happens?

Here is the PrintScreen:

According to new design method followed in android studio for android development you cannot add any elements to the activity_main.xml. Rather you should add them to content_main.xml.

You can learn more about it from this answer.

You can stop it from happening.
Answered by 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.

how do I create an Empty Activity with a Fragment?

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.

I had same problem. In the design page, I saw error message "Render Error..." I click Android Studio->check for update->update and restart After android studio update, the drag&drop from Palette to design page works.

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

It works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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