Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android LinearLayout: not displaying correct height

I have a LinearLayout with a white background,filled with a bunch of LinearLayouts and RelativeLayouts. I've tried to set the parent layout to have a minimum height, but it still seems to be wrapping to the content.

Here's a picture of what it looks like now. The white space should have a set minimum height that is greater than it is now. enter image description here

Here's what I think is a relevant section of the xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contactViewScrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ABABAB" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="300dip"
        android:background="#FFFFFF"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/contactHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#EDEDED"
            android:paddingLeft="10dp" >

            <TextView
                android:id="@+id/fullName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="175dip"
                android:paddingTop="5dp"
                android:textSize="18sp" />

            <View
                android:layout_width="1dp"
                android:layout_height="90dp"
                android:layout_toLeftOf="@+id/image"
                android:background="#000000" />

            <ImageView
                android:id="@+id/image"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentRight="true"
                android:background="#D6D6D6"
                android:contentDescription="@string/contact_image_description"
                android:scaleType="centerCrop" />
        </RelativeLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#000000" />

        <LinearLayout
            android:id="@+id/mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="10dp" >

            <TextView
                android:id="@+id/mobilePhoneHeading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingTop="15dp"
                android:text="@string/mobile_phone"
                android:textColor="#787878" />

            <TextView
                android:id="@+id/mobilePhone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:paddingTop="2dp"
                android:textSize="18sp" />
        </LinearLayout>

... and many other LinearLayouts, all set to 'GONE' programmatically.

Can anyone suggest a fix? I can't figure out why that white section is taking up so little space.

like image 791
false_azure Avatar asked Jul 02 '26 09:07

false_azure


1 Answers

// try this
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contactViewScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ABABAB" >

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="#FFFFFF"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/contactHeader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#EDEDED"
                android:paddingLeft="10dp" >

                <TextView
                    android:id="@+id/fullName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="175dp"
                    android:paddingTop="5dp"
                    android:textSize="18sp" />

                <View
                    android:layout_width="1dp"
                    android:layout_height="90dp"
                    android:layout_toLeftOf="@id/image"
                    android:background="#000000" />

                <ImageView
                    android:id="@+id/image"
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:layout_alignParentRight="true"
                    android:background="#D6D6D6"
                    android:contentDescription="contact_image_description"
                    android:scaleType="centerCrop" />
            </RelativeLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="#000000" />

            <LinearLayout
                android:id="@+id/mobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="10dp" >

                <TextView
                    android:id="@+id/mobilePhoneHeading"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="15dp"
                    android:text="mobile_phone"
                    android:textColor="#787878" />

                <TextView
                    android:id="@+id/mobilePhone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="10dp"
                    android:paddingTop="2dp"
                    android:textSize="18sp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>
like image 60
Haresh Chhelana Avatar answered Jul 04 '26 22:07

Haresh Chhelana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!