I am trying to add a Button
in a LinearLayout
after a TextView
but it is not showing up.
Here is my layout code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="45dip">
<TextView android:layout_width="fill_parent"
android:layout_height="45dip"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:textStyle="bold"
android:textSize="17dip"
android:gravity="center_vertical"
android:id="@+id/tvChild"
android:text="Children"
android:textColor="#ffCCCC22" />
<Button android:id="@+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Submit" />
</LinearLayout>
The TextView
is displayed correctly with proper text but instead of a Button
I am getting a big blank space of three to four lines length.
What am I missing?
The problem was you were setting
android:layout_width="fill_parent"
for theTextView
, so it took full screen width just for displaying theTextView
. And it was not able to display theButton
.Here are two options for you :
Adding
TextView
andButton
on a single row.Change the
layout_width
attribute of theTextView
towrap_content
.Adding
TextView
andButton
vertically.Change
LinearLayout
's orientation attribute tovertical
.Try this.
Use
android:layout_width="wrap_content"
instead ofandroid:layout_width="fill_parent"
forTextView
andButton