Drag/Drop feature in Android studio not working

2019-01-22 18:13发布

问题:

I'm new to android programming The drag/ and drop feature in android studio is not working. I can't drag anything to my phone. Right now my fragment is google map view and i want to add a search bar to the view. It just doesn't drag. When I try to add it in text it says element item not allowed here?

This is my activity_maps.xml file

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment">
<item android:id="@+id/search"
    android:title="@string/search_title"
    android:icon="@drawable/ic_search"
    android:showAsAction="collapseActionView|ifRoom"
    android:actionViewClass="android.widget.SearchView" />
</fragment>

回答1:

the new version of android studio uses 2 xml files for each layout. One (e.g. content_main.xml) embedded in the other one (Activity_main.xml). you should open the content_*.xml and do the design in it. hope it helps.



回答2:

The drag and drop feature is not working in Android Studio.... I also wasted a lot of time searching...what fixed my problem was to select a Theme for the Activity.

The image below will make things clear.



回答3:

In addition to Hamed's answer I also had to:

File > Invalidate Caches / Restart ...

I'm missing vim.



回答4:

After updating to the latest version of Android Studio (2.2) I started having this problem.

After some searching and playing around I discovered holding down alt allows my to drag and drop. I had the "hold ALT to drag and drop" option checked under Settings-> Appearance & Behavior > Appearance.

Either I had already selected this option and a fix in Android Studio 2.2 made it so the option applied to dragging and dropping with the palette panel OR this option was recently added and defaulted to checked or a problem happened while upgrading that set it to true.

I have this option set in IntelliJ and have used the android studio palette normally before and am mostly sure I used it without having to hold down alt before so I'm going with option A (and it took me an embarrassing amount of time until I tried holding down alt).



回答5:

In my case, I was using ConstraintLayout in Android Studio 3.0. Fixed it by using android.support.constraint.ConstraintLayout instead.



回答6:

I faced this problem also and I simply fixed that by changing the theme to DeviceDefault.Light for the activity.



回答7:

I also faced the same problem. The culprit was that in my parent android.support.wearable.view.BoxInsetLayout tag i was dragging the components directly but when i put
FrameLayout inside android.support.wearable.view.BoxInsetLayout tag and then drag my components to FrameLayout it worked .

Hope it will help someone.



回答8:

I know this is old but not being able to drag elements into the design just happened to me (2/18/18). Restarting Android Studio (3.01) did the trick.



回答9:

Go to your "values" folder and open the "styles.xml" file. Replace "Theme.AppCompat.Light.DarkActionBar" under the parent tag with "Base.Theme.AppCompat.Light.DarkActionBar"



回答10:

Figured it out I figured it out. Even though the design panel is visible as well as the Palette and Component Tree I ALSO need to have app/src/main/res/layout/fragment_main.xml selected over in the Project panel in order for the actual design of the layout to be enabled.



回答11:

Drag 'n' Drop may not work properly, when you have a LinearLayout, in that condition, the items you drag will try to settle in a specific manner(Horizontal or Vertical), instead try to change your main layout to Relative Layout

Linear Layout --> Relative Layout



回答12:

I know this is a old issue,none of these were working for me, and it so happened that it wasn't android studio that was giving this problem it was windows. I noticed I couldn't drag anything so clicking and holding any file on the desktop and pressing escape is what fixed it for me.



回答13:

I faced the same problem of not dragging elements in Android Studio 3.1.

Restarting the Android Studio, fixed the problem for me



回答14:

I resolve this problem by simply rebuild my android studio project.



回答15:

I was also confused with the drag&drop feature. Until I figured out:

After beginning to drag you have to release the mouse button and everything works fine.

Nice feature - a bit unusual though.