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?
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
Weight can only be used in LinearLayout . If the orientation of linearlayout is Vertical, then use android:layout_height="0dp" and if the orientation is horizontal, then use android:layout_width = "0dp" . It'll work perfectly.
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
ScrollView : is a special type of FrameLayout in that it allows users to scroll through a list of views that occupy more space than the physical display. The ScrollView can contain only one child view or ViewGroup, which normally is a LinearLayout. ListView : is a view group that displays a list of scrollable item.
Try this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="45dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_width="wrap_content"
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="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Submit" />
</LinearLayout>
Use android:layout_width="wrap_content"
instead of
android:layout_width="fill_parent"
for TextView
and Button
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With