简体   繁体   中英

Date picker does not scroll properly inside scrollView

I have coded a layout for android dialog. There is a date picker inside a scrollView. When I am trying to change the date by scrolling, it does not work properly. Date-picker gets stuck.
My layout is below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dp" >

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

        <TextView
            android:id="@+id/text_lang_payment_method"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:text="Payment Method :"
            android:textSize="20sp" />

        <Spinner
            android:id="@+id/spinnerPaymentMethod"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2" />
    </LinearLayout>


    <LinearLayout
                    android:id="@+id/chequeLayout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:weightSum="6" >

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

                        <TextView
                            android:id="@+id/text_chequeno_lang"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="2"
                            android:gravity="center_vertical"
                            android:text="Cheque No:"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textSize="20dp" />

                        <EditText
                            android:id="@+id/inputChequeNo"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_alignParentEnd="true"
                            android:layout_alignParentRight="true"
                            android:layout_alignParentTop="true"
                            android:layout_toRightOf="@+id/textView10"
                            android:layout_weight="2"
                            android:ems="10"
                            android:inputType="number" />
                    </LinearLayout>

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

                        <TextView
                            android:id="@+id/text_Cheque_date_lang"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_alignParentStart="true"
                            android:layout_weight="1"
                            android:gravity="center_vertical"
                            android:text="Cheque Date:"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textSize="20dp" />

                        <DatePicker
                            android:id="@+id/dpResult"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:calendarViewShown="false" />
                    </LinearLayout>

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

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

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

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

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

                        <TextView
                            android:id="@+id/text_lang_cheque_amount"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="2"
                            android:gravity="center_vertical"
                            android:text="Cheque Amount :"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textSize="20sp" />

                        <EditText
                            android:id="@+id/inputChequeAmount"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="2"
                            android:inputType="numberDecimal" />
                    </LinearLayout>
                </LinearLayout>



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

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

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

    <Button
        android:id="@+id/button_add_payment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/yellobutton"
        android:text="Add Payment" />

    <Button
        android:id="@+id/button_cancel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="@drawable/yellobutton"
        android:text="Cancel" />

</LinearLayout>

How do I fix this?

Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:padding="5dp" >

    <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="5dp" >

        <LinearLayout
            android:layout_width="204dp"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

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

                <TextView
                    android:id="@+id/text_lang_payment_method"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="2"
                    android:text="Payment Method :"
                    android:textSize="20sp" />

                <Spinner
                    android:id="@+id/spinnerPaymentMethod"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="2" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/chequeLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:weightSum="6" >

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

                    <TextView
                        android:id="@+id/text_chequeno_lang"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:text="Cheque No:"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textSize="20dp" />

                    <EditText
                        android:id="@+id/inputChequeNo"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:ems="10"
                        android:inputType="number" />
                </LinearLayout>

                <ScrollView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >

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

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

                            <TextView
                                android:id="@+id/text_Cheque_date_lang"
                                android:layout_width="70dp"
                                android:layout_height="match_parent"
                                android:layout_alignParentStart="true"
                                android:gravity="center_vertical"
                                android:text="Cheque Date:"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:textSize="20dp" />

                            <DatePicker
                                android:id="@+id/dpResult"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:calendarViewShown="false" />
                        </LinearLayout>
                    </LinearLayout>
                </ScrollView>



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

                    <TextView
                        android:id="@+id/text_lang_cheque_amount"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:gravity="center_vertical"
                        android:text="Cheque Amount :"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textSize="20sp" />

                    <EditText
                        android:id="@+id/inputChequeAmount"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="2"
                        android:inputType="numberDecimal" />
                </LinearLayout>
            </LinearLayout>

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

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

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

            <Button
                android:id="@+id/button_add_payment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:text="Add Payment" />

            <Button
                android:id="@+id/button_cancel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:text="Cancel" />
        </LinearLayout>
    </HorizontalScrollView>

</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM