Reputation: 1
I use the following main.xml
code but I can only see one edit text box
I need help regarding why does this occur? I have tried many times but I cannot see proper edit box and all other components
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="ENTER THE PHONE NUMBER HERE" />
<EditText
android:id="@+id/txtPhoneNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Message"
/>
<EditText
android:id="@+id/txtMessage"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:gravity="top"
/>
<Button
android:id="@+id/btnSendSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send SMS"
/>
Upvotes: 0
Views: 139
Reputation: 44571
This is because you haven't set an orientation for your LinearLayout
and the default is horizontal. Since you have all of your views width set to fill_parent
, there is no room for the others
You have a couple options. You can either set
android:orientation="vertical"
in your root LinearLayout
or you can change the width of these views
android:layout_width="wrap_content"
There are other ways too, obviously, but these are the easiest fixes for what you have
Also Note:
FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)
Side Note
I see you are using hard-coded strings in your xml. Eclipse will warn you about this and it may give you headaches in the future if you don't get accustomed to using the strings.xml
folder and using the android:text="@string/string_name"
Upvotes: 1