I have the following layout for a dialog (I need to get user's birthday information) :
<?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>
It looks as follows :
The problem is when the user has to pick a date from the date picker, the scroll input sometimes goes to the enclosing scroll view (I have scroll view as the linear layout proves too long for the screen size I am testing on).
How can I make sure that when user scrolls over date picker that the entire layout doesn't scroll ?
I just extended the DatePicker class and override the onInterceptTouchEvent as one member here shared. https://stackoverflow.com/a/9687545
public class CustomDatePicker extends DatePicker {
public CustomDatePicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
{
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}
Then you just use it like this:
<pt.example.appYoumade.CustomDatePicker
android:id="@+id/docEnd_datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"/>
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.