【发布时间】:2025-12-07 06:05:02
【问题描述】:
我有以下对话框布局(我需要获取用户的生日信息):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Where were you born ?"
android:id="@+id/textView_BirthPlace"
android:textStyle="bold"
android:textSize="13dp"
android:textColor="@color/heading_text_color"
android:layout_margin="20dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What time were you born ?"
android:id="@+id/textView_BirthTime"
android:textStyle="bold"
android:textSize="13dp"
android:textColor="@color/heading_text_color"
android:layout_margin="20dp"/>
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timePicker"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="When were you born ?"
android:id="@+id/textView_BirthDate"
android:textStyle="bold"
android:textSize="13dp"
android:textColor="@color/heading_text_color"
android:layout_margin="20dp"/>
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datePicker"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"/>
</LinearLayout>
</ScrollView>
如下所示:
问题是当用户必须从日期选择器中选择一个日期时,滚动输入有时会转到封闭的滚动视图(我有滚动视图,因为线性布局证明对于我正在测试的屏幕尺寸来说太长了) .
如何确保当用户滚动日期选择器时整个布局不会滚动?
【问题讨论】:
-
我遇到了同样的问题,不幸的是我不得不使用 DatePickerDialog 并且它可以正常工作。 Good example 和 another example