简体   繁体   中英

android - Why my editText doesn't show?

Hi everyone needs help here.

I don't understand why my editText is not showing up. What Im so puzzled about is that I can see at my eclipse outline the editText.

Here are my codes:

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

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

Im an absolute noob to android so please be patient. Please point out to me what Im doing wrong.

因为你已经在你的按钮中传递了android:layout_width="fill_parent"并且占据了你屏幕的整个宽度。要么将LinearLayoutandroid:orientation="horizontal"属性更改为vertical,要么将android:layout_width="fill_parent"更改为wrap_content

Try this.

Change your orientation of LinearLayout to "vertical". Then they will be aligned vertically. This is happening because you are setting layout_width="fill_parent" in your Button which will fill the entire parent and thus will not show your EditText box.

Let me thinks what exactly you want to do?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM