3D-kreativ
3D-kreativ

Reputation: 9297

Can't add form widgets to main.xml file Graphical Layout

I'm new to Android and I wonder why I can't drag and drop things like buttons to the display in the main.xml Graphical Layout? It seems like it's locked or something else that I can't figure out on myself. Help is preciated! Thanks!

EDIT: This is my code in xml file

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:text="@string/hello"
 />

Upvotes: 3

Views: 9723

Answers (4)

user5487182
user5487182

Reputation: 1

I am a begginer Android Studio to. I have same problem about drag and drop in design screen (in GUI). I solve the problem by using "res/layout/content_main.xml" (left side of the screen). It works! but ı am not sure that is it the right way :)))

Upvotes: 0

Abhishek
Abhishek

Reputation: 1

Drag and drop the elements onto the Outline area instead of the display itself.Worked for me.

Upvotes: -1

Ghost
Ghost

Reputation: 3966

You are not able to do so because you don't have a Layout in your XML. Given here is an example as to how to build a basic layout. You can also refer to the Relative Layout tutorial or Linear Layout tutorial for more details, as these are widely used layouts.

Given below is the sample code for your XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

You can replace Linear Layout with Relative Layout at your convenience. But do keep in mind that you can't use the graphical layout without having a layout. To drag and drop a layout, refer the image below:

enter image description here

Hope this helps.

Upvotes: 6

corylulu
corylulu

Reputation: 3499

If that's your code, then it seems that you might be trying to drag elements into the TextView since it is filling the entire layout. Try to remove the TextView and see if you are then able to drag and drop elements again. Either that or change it to:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textview"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/hello"
 />

Upvotes: 0

Related Questions