2012-08-10 131 views
1

嗨,大家需要幫助。android - 爲什麼我的editText不顯示?

我不明白爲什麼我的editText沒有顯示出來。我感到困惑的是,我可以在我的日食大綱中看到editText。

這裏是我的代碼:

activity_main.xml

<LinearLayout 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:orientation="horizontal" > 

<Button 
    android:id="@+id/buttonTESTER1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/btnTester1_text" 
/> 

<EditText 
    android:id="@+id/editTextTESTER1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="@string/editTextHINT1" 
    android:inputType="text" 
/> 

</LinearLayout> 

strings.xml

<resources> 

<string name="app_name">Android Tutorial</string> 
<string name="hello_world">Hello world!</string> 
<string name="menu_settings">Settings</string> 
<string name="title_activity_main">MainActivity</string> 
<string name="btnTester1_text">BUTTON TESTER</string> 
<string name="editTextTester1_text">BUTTON TESTER</string> 
<string name="editTextHINT1">Test</string> 

</resources> 

我是一位絕對的菜鳥到Android所以請耐心等待。請指出我做錯了什麼。

+0

告訴我們在哪兒你設置'的setContentView(R.layout.activity_main)代碼'在你的java文件 – Praveenkumar 2012-08-10 05:31:30

+0

@SpK哪一個? MainActivity.java或R.java?我不知道哪個文件。 – AndroidMoron 2012-08-10 05:33:18

+0

將按鈕的android:layout_width =「fill_parent」更改爲android:layout_width =「wrap_content」 – 2012-08-10 05:35:01

回答

4

因爲你已經在你的按鈕,通過android:layout_width="fill_parent"和其採取的screen.Either的整個寬度的LinearLayoutandroid:orientation="horizontal"屬性更改爲垂直或android:layout_width="fill_parent"wrap_content

+0

爲什麼editText在按鈕下面?我雖然它的行爲像一個瀏覽器。 – AndroidMoron 2012-08-10 05:35:37

+1

謝謝兄弟!我將android方向更改爲垂直方向。你搖滾! – AndroidMoron 2012-08-10 05:37:29

+0

如果你改變方向,那麼它會在下面,如果沒有,並且只是改變fill_parent爲wrap_content,那麼它將並排 – Akram 2012-08-10 05:39:09

0

試試這個。

將LinearLayout的方向更改爲「垂直」。然後它們將被垂直對齊。 這是因爲你在你的Button中設置了layout_width =「fill_parent」,它將填充整個父項,因此不會顯示你的EditText框。

0

讓我想想你到底想要做什麼?

<LinearLayout 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:orientation="vertical" > 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
    <Button 
     android:id="@+id/buttonTESTER1" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:text="@string/btnTester1_text" 
    /> 

    <EditText 
     android:id="@+id/editTextTESTER1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:hint="@string/editTextHINT1" 
     android:inputType="text" 
    /> 

    </LinearLayout> 
    </LinearLayout> 
+0

試試這個。它一定會奏效 – 2012-08-10 05:46:50