Henry Ing-Simmons
Henry Ing-Simmons

Reputation: 1501

TextViews and other elements not being displayed

I have a layout with a view text views, a table and then some buttons at the bottom. I wanted the buttons to always be at the bottom regardless of the height of the table so I changed the layout to relative so I could do this.

However this mashed all the textviews and the table into one line. So I put these in a LinearLayout within the RelativeLayout which I thought would fix the problem. Problem now is that only the first TextView and the buttons at the bottom show up. Everything else is missing.

Here is the xml code I am using to define this layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="4dip"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <TextView
            android:id="@+id/view_meal_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Spaghetti Bolognaise"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/view_meal_type"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Dinner"
            android:textSize="16sp" />

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_toLeftOf="@+id/view_day_calories"
                android:text="@string/calories_label"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/view_day_calories"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="@string/calories_today_value"
                android:textSize="18sp" />
        </RelativeLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:layout_marginBottom="10dip"
            android:background="@color/hr" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TableLayout
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/tableLayout1"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dip"
                    android:layout_marginRight="10dip"
                    android:stretchColumns="0,1,2" >

                    <TableRow
                         android:id="@+id/tableRow1"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content" >

                        <TextView
                            android:id="@+id/meal_table_ingred_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/ingredient"
                            android:textAppearance="?android:attr/textAppearanceMedium" />

                        <TextView
                            android:id="@+id/meal_table_quantity_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/quantity"
                            android:textAppearance="?android:attr/textAppearanceMedium" />

                        <TextView
                            android:id="@+id/meal_table_calories_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/calories"
                            android:textAppearance="?android:attr/textAppearanceMedium" />
                    </TableRow>
                </TableLayout>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="1.0" >

        <Button
            android:id="@+id/edit_meal_button"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="@string/edit_meal_label" />

        <Button
            android:id="@+id/favourite_meal_button"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="@string/favourite_meal_label" />
    </LinearLayout>

</RelativeLayout>

Thanks for your help!

Upvotes: 0

Views: 61

Answers (1)

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

Change

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true">

to

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

Upvotes: 2

Related Questions