Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android match_parent not working as expected

Tags:

android

In my layout file I use root ScrollViewand child LinearLayout.

I searched about this but did't get help. I set match_parent in my both parent and child view.

But there is problem with child view.

Child view not filling like parent view.

Here is image and xml code.

enter image description here

Layout File.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:CustomTextView="http://schemas.android.com/apk/res-auto"
    xmlns:CustomEditTextView="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#D3D6DB"
    android:orientation="vertical"
    tools:context=".tabs.MyTravelTab" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/card_background_new"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp" >

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="@dimen/field_height"
                    android:layout_weight="0.4"
                    android:gravity="left|center_vertical" >

                    <com.mymv.controls.CustomTextView
                        android:id="@+id/textGPS"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        CustomTextView:typeface="Roboto-Regular.ttf"
                        android:text="ABC"
                        android:textColor="@color/black"
                        android:textSize="12sp" />

                    <ToggleButton
                        android:id="@+id/gps_toggle"
                        android:layout_width="wrap_content"
                        android:layout_height="24dp"
                        android:layout_margin="5dp"
                        android:background="@drawable/gps_custom_toggle"
                        android:checked="false"
                        android:textOff=""
                        android:textOn="" />

                    <com.mymv.controls.CustomTextView
                        android:id="@+id/textManual"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        CustomTextView:typeface="Roboto-Regular.ttf"
                        android:text="DEF"
                        android:textColor="@color/black"
                        android:textSize="11sp" />
                </LinearLayout>

                <Spinner
                    android:id="@+id/spinnerPurposeOfJourney"
                    android:layout_width="0dp"
                    android:layout_height="@dimen/field_height"
                    android:layout_weight="0.6"
                    android:background="@drawable/dropdown_black_border"
                    android:entries="@array/purpose_of_journey" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/gpsLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:visibility="gone" >

                <LinearLayout
                    android:id="@+id/startGPSBtn"
                    android:layout_width="0dp"
                    android:layout_height="@dimen/field_height"
                    android:layout_weight="0.5"
                    android:background="@drawable/textview_green_drawable_left_curve_selector"
                    android:gravity="center" >

                    <ImageView
                        android:id="@+id/imageView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/gps" />

                    <com.mymv.controls.CustomTextView
                        android:id="@+id/textView1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        CustomTextView:typeface="Roboto-Regular.ttf"
                        android:text="START GPS"
                        android:textColor="@color/white" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/endGPSBtn"
                    android:layout_width="0dp"
                    android:layout_height="@dimen/field_height"
                    android:layout_weight="0.5"
                    android:background="@drawable/textview_red_drawable_right_curve_selector"
                    android:gravity="center" >

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/end_flag" />

                    <com.mymv.controls.CustomTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        CustomTextView:typeface="Roboto-Regular.ttf"
                        android:text="END GPS"
                        android:textColor="@color/white" />
                </LinearLayout>
            </LinearLayout>

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center" >

                    <com.mymv.controls.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="@dimen/field_height"
                        android:layout_weight="@integer/layout_weight_textview"
                        CustomTextView:typeface="Roboto-Bold.ttf"
                        android:background="@drawable/textview_gray_drawable"
                        android:gravity="center_vertical"
                        android:padding="5dp"
                        android:text="DATA"
                        android:textColor="@color/gray" />

                    <com.mymv.controls.CustomTextView
                        android:id="@+id/edtTxtDate"
                        android:layout_width="0dp"
                        android:layout_height="@dimen/field_height"
                        android:layout_marginLeft="-1dp"
                        android:layout_weight="@integer/layout_weight_edittext"
                        CustomTextView:typeface="Roboto-Regular.ttf"
                        android:background="@drawable/edittext_drawable_right_curv_selector"
                        android:gravity="center_vertical"
                        android:hint="DATA"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:textColor="@color/black"
                        android:textColorHint="@color/gray"
                        android:textSize="15dp" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/manualLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="visible" >

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:gravity="center" >

                        <com.mymv.controls.CustomTextView
                            android:layout_width="0dp"
                            android:layout_height="@dimen/field_height"
                            android:layout_weight="@integer/layout_weight_textview"
                            CustomTextView:typeface="Roboto-Bold.ttf"
                            android:background="@drawable/textview_gray_drawable"
                            android:gravity="center_vertical"
                            android:padding="5dp"
                            android:text="DATA"
                            android:textColor="@color/gray" />

                        <com.mymv.controls.CustomEditTextView
                            android:id="@+id/edtTxtStartOdometer"
                            android:layout_width="0dp"
                            android:layout_height="@dimen/field_height"
                            android:layout_marginLeft="-1dp"
                            android:layout_weight="@integer/layout_weight_edittext"
                            CustomTextView:typeface="Roboto-Regular.ttf"
                            android:background="@drawable/edittext_drawable_right_curv_selector"
                            android:focusable="false"
                            android:gravity="center_vertical"
                            android:hint="DATA"
                            android:inputType="number"
                            android:maxLength="6"
                            android:padding="5dp"
                            android:singleLine="true"
                            android:textColor="@color/black"
                            android:textColorHint="@color/gray"
                            android:textSize="15dp" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:gravity="center" >

                        <com.mymv.controls.CustomTextView
                            android:layout_width="0dp"
                            android:layout_height="@dimen/field_height"
                            android:layout_weight="@integer/layout_weight_textview"
                            CustomTextView:typeface="Roboto-Bold.ttf"
                            android:background="@drawable/textview_gray_drawable"
                            android:gravity="center_vertical"
                            android:padding="5dp"
                            android:text="DATA"
                            android:textColor="@color/gray" />

                        <com.mymv.controls.CustomEditTextView
                            android:id="@+id/edtTxtEndOdometer"
                            android:layout_width="0dp"
                            android:layout_height="@dimen/field_height"
                            android:layout_marginLeft="-1dp"
                            android:layout_weight="@integer/layout_weight_edittext"
                            CustomEditTextView:typeface="Roboto-Regular.ttf"
                            android:background="@drawable/edittext_drawable_right_curv_selector"
                            android:focusable="false"
                            android:gravity="center_vertical"
                            android:hint="DATA"
                            android:inputType="number"
                            android:maxLength="6"
                            android:padding="5dp"
                            android:singleLine="true"
                            android:textColor="@color/black"
                            android:textColorHint="@color/gray"
                            android:textSize="15dp" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center" >

                    <com.mymv.controls.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="@dimen/field_height"
                        android:layout_weight="@integer/layout_weight_textview"
                        CustomTextView:typeface="Roboto-Bold.ttf"
                        android:background="@drawable/textview_gray_drawable"
                        android:gravity="center_vertical"
                        android:padding="5dp"
                        android:text="DATA"
                        android:textColor="@color/gray" />

                    <com.mymv.controls.CustomEditTextView
                        android:id="@+id/edtTxtStartLocation"
                        android:layout_width="0dp"
                        android:layout_height="@dimen/field_height"
                        android:layout_marginLeft="-1dp"
                        android:layout_weight="@integer/layout_weight_edittext"
                        CustomEditTextView:typeface="Roboto-Regular.ttf"
                        android:background="@drawable/edittext_drawable_right_curv_selector"
                        android:focusable="false"
                        android:gravity="center_vertical"
                        android:hint="DATA"
                        android:maxLength="100"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:textColor="@color/black"
                        android:textColorHint="@color/gray"
                        android:textSize="15dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:gravity="center" >

                    <com.mymv.controls.CustomTextView
                        android:layout_width="0dp"
                        android:layout_height="@dimen/field_height"
                        android:layout_weight="@integer/layout_weight_textview"
                        CustomTextView:typeface="Roboto-Bold.ttf"
                        android:background="@drawable/textview_gray_drawable"
                        android:gravity="center_vertical"
                        android:padding="5dp"
                        android:text="DATA"
                        android:textColor="@color/gray" />

                    <com.mymv.controls.CustomEditTextView
                        android:id="@+id/edtTxtEndLocation"
                        android:layout_width="0dp"
                        android:layout_height="@dimen/field_height"
                        android:layout_marginLeft="-1dp"
                        android:layout_weight="@integer/layout_weight_edittext"
                        CustomEditTextView:typeface="Roboto-Regular.ttf"
                        android:background="@drawable/edittext_drawable_right_curv_selector"
                        android:focusable="false"
                        android:gravity="center_vertical"
                        android:hint="DATA"
                        android:maxLength="100"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:textColor="@color/black"
                        android:textColorHint="@color/gray"
                        android:textSize="15dp" />
                </LinearLayout>

                <Button
                    android:id="@+id/btnRecord"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/field_height"
                    android:layout_marginTop="10dp"
                    android:background="@drawable/button_blue_border"
                    android:text="Button"
                    android:textColor="@color/white"
                    android:textSize="15dp" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/viewUsage"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="0.5"
                android:background="@drawable/button_background_yellow"
                android:padding="10dp"
                android:text="Button1"
                android:textColor="@color/black" />

            <Button
                android:id="@+id/viewTravelHistory"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="0.5"
                android:background="@drawable/button_background_blue"
                android:padding="10dp"
                android:text="Button2"
                android:textColor="@color/white" />
        </LinearLayout>
    </LinearLayout>

</ScrollView>
like image 840
Chirag Savsani Avatar asked Mar 11 '26 14:03

Chirag Savsani


1 Answers

Try android:fillViewport="true" in your scrollview.

like image 149
Neo Avatar answered Mar 13 '26 03:03

Neo



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!