anu
anu

Reputation: 719

Drag/Drop feature in Android studio not working

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>

Upvotes: 42

Views: 85760

Answers (19)

Ramya Bm
Ramya Bm

Reputation: 19

File>Settings>Appearance and Behavior>Appearance>Theme -> IntelliJ Light

Change your settings to the above path. Then you can drag and drop the views on the design view.

Upvotes: 0

Will Chartrand
Will Chartrand

Reputation: 1

I just downloaded Android Studio and ran into this problem. After clicking random buttons for a few minutes I found out:

There's a magnet icon in the toolbar right above the design view called "Disable Autoconnection to Parent". After I clicked this I was able to move the button wherever.

Upvotes: -1

Saksham Choudhary
Saksham Choudhary

Reputation: 11

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.

Upvotes: 1

John Xenakis
John Xenakis

Reputation: 221

I have did everything in this post, until I've run android studio by just running and not running with "Run As Administrator"(Right Click -> More -> Run As Administrator). I've used to run android studio with "Run As Administrator" and that caused the problem to not drag and drop. Just run Android Studio without "Run As Administrator".

Or try do vice versa and actually "Run As Administrator" if you already just running it without "Run As Administrator".

Upvotes: 0

shreya kadam
shreya kadam

Reputation: 1

I was facing the same problem,but then I found the solution . All you have to do is select the element you want to add(eg. Button) and press "Enter". The component will be displayed on your screen.

Or you can select the component and right click -> Add to Design

Upvotes: 0

Manthan_Admane
Manthan_Admane

Reputation: 449

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"

Upvotes: 3

mehmoodnisar125
mehmoodnisar125

Reputation: 1529

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

Upvotes: 0

Waqar UlHaq
Waqar UlHaq

Reputation: 6422

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

Restarting the Android Studio, fixed the problem for me

Upvotes: 1

Marty
Marty

Reputation: 11

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.

Upvotes: 1

Mon
Mon

Reputation: 1110

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

Upvotes: 3

Jakob Hartman
Jakob Hartman

Reputation: 366

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.

Upvotes: 0

Shubham Kushwah
Shubham Kushwah

Reputation: 655

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

Upvotes: 0

meese
meese

Reputation: 381

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.

enter image description here

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).

Upvotes: 10

Drew LeSueur
Drew LeSueur

Reputation: 20145

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

File > Invalidate Caches / Restart ...

I'm missing vim.

Upvotes: 25

Sukh
Sukh

Reputation: 540

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.

Upvotes: 1

Gernot Ullrich
Gernot Ullrich

Reputation: 817

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.

Upvotes: -1

Hamed
Hamed

Reputation: 446

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.

Upvotes: 43

Jasmine
Jasmine

Reputation: 222

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

Upvotes: 2

Vishal Kumar
Vishal Kumar

Reputation: 4617

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. enter image description here

Upvotes: 20

Related Questions