android - 为什么我的editText没有显示?

时间:2020-12-24 21:14:26

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.

我不明白为什么我的editText没有出现。我很困惑的是,我可以在我的日食大纲中看到editText。

Here are my codes:

这是我的代码:

activity_main.xml

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

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>

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

我是一个绝对的菜鸟,所以请耐心等待。请指出我做错了什么。

3 个解决方案

#1


4  

Because you have passed android:layout_width="fill_parent" in your button and its taking whole width of your screen.Either change the android:orientation="horizontal"property of LinearLayout to vertical or android:layout_width="fill_parent" to wrap_content.

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

#2


0  

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.

将LinearLayout的方向更改为“垂直”。然后它们将垂直对齐。发生这种情况是因为您在Button中设置了layout_width =“fill_parent”,它将填充整个父级,因此不会显示您的EditText框。

#3


0  

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>

#1


4  

Because you have passed android:layout_width="fill_parent" in your button and its taking whole width of your screen.Either change the android:orientation="horizontal"property of LinearLayout to vertical or android:layout_width="fill_parent" to wrap_content.

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

#2


0  

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.

将LinearLayout的方向更改为“垂直”。然后它们将垂直对齐。发生这种情况是因为您在Button中设置了layout_width =“fill_parent”,它将填充整个父级,因此不会显示您的EditText框。

#3


0  

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>