Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button not displaying in LinearLayout

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?

like image 818
Codemator Avatar asked Aug 04 '11 09:08

Codemator


People also ask

How to use LinearLayout in android studio?

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

How to give weight to LinearLayout in android?

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.

What is Relative layout in android?

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

Which of the following layout is used to display the single child view?

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.


1 Answers

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

like image 180
Niranj Patel Avatar answered Oct 18 '22 14:10

Niranj Patel