2012-01-31 20 views
3

我是新來的Android,我想知道爲什麼我不能拖放像按鈕的東西到main.xml圖形佈局中的顯示?它似乎被鎖定,或者是我無法想象的其他東西。幫助是preciated!謝謝!無法添加窗體小部件到main.xml文件圖形佈局

編輯:這是我在XML文件中的代碼

<?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" 
/> 
+0

請務必更新Android。如果您最近更新了eclipse,他們在8.x中做了一些重大更改,這需要對Android部分進行一些更改。 – Corylulu 2012-01-31 18:31:12

+0

但我剛剛安裝了Android SDK。問題是我可以在幾個小時前添加按鈕,但現在看起來不可能!它可以用別的東西來代表嗎?我相信這只是我做錯了什麼 – 2012-01-31 18:37:03

+0

你的main.xml文件中的代碼是什麼? – 2012-01-31 19:54:13

回答

6

你不能這樣做,因爲你沒有在你的XML一個Layout做。 Given here是一個如何構建基本佈局的例子。您也可以參考Relative Layout tutorialLinear Layout tutorial瞭解更多詳情,因爲這些是廣泛使用的佈局。

下面給出的是你的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> 

你可以在方便的時候更換Linear LayoutRelative Layout。但請記住,不能使用沒有佈局的圖形佈局。要拖放佈局,參考下圖:

enter image description here

希望這有助於。

0

如果這是你的代碼的話,好像你可能試圖拖動元素融入TextView的,因爲它充滿整個佈局。嘗試刪除TextView,看看你是否能夠再次拖拽元素。如果不是這樣,將其更改爲:

<?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" 
/> 
+0

與我已有的代碼不一樣嗎?不,它沒有工作,這個新代碼 – 2012-01-31 21:05:07

+0

不,我改變它,所以高度沒有fill_parent。我懷疑你的TextView在兩個方向上完全fill_parent,這是造成這個問題的原因。你有沒有嘗試刪除TextView? – Corylulu 2012-01-31 21:11:32

+0

是的,我試圖刪除它,然後我沒有屏幕拖放所有!? – 2012-01-31 21:13:15

-1

將元素拖放到Outline區域而不是顯示器本身。爲我工作。

0

我是一個begginer Android Studio。我在設計屏幕(在GUI中)拖放有同樣的問題。我通過使用「res/layout/content_main.xml」(屏幕左側)來解決問題。有用!但我不知道這是正確的方式:)))

相關問題