日期选择器无法在scrollView内正确滚动

时间:2014-09-04 09:28:17

标签: android android-layout

我为android对话框编写了一个布局。 scrollView中有一个日期选择器。当我尝试通过滚动更改日期时,它无法正常工作。日期选择器卡住了。
我的布局如下:

<?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>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

试试这个:

<?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>