jjobes / SlideDateTimePicker

A combined DatePicker and TimePicker in a DialogFragment for Android
Apache License 2.0
836 stars 235 forks source link

Wrong way of setting ViewPager height #16

Closed alexrainman closed 8 years ago

alexrainman commented 8 years ago

The way you set the ViewPager height OnMeasure makes the DatePicker move to the left when you touch it.

Replace it with this code:

int height = 0;
for(int i = 0; i < getChildCount(); i++) {
    View child = getChildAt(i);
    child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int h = child.getMeasuredHeight();
    if(h > height) height = h;
}

heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

And problem fixed!

jjobes commented 8 years ago

Hey Alex,

Could you please give me some more details about what exactly the error is and how to reproduce it?

I'm not sure what you mean by "makes the DatePicker move to the left when you touch it".

Thanks!

Jason

alexrainman commented 8 years ago

I updated the library to the latest SDK version. When you touch the DatePicker and change the date, somehow it's height change and, instead of being centered it gets moved to the left (aligned to the left). I changed the code with the one i provided and the issue is gone :)

jjobes commented 8 years ago

Can you give me the details of the device you saw the error on?

alexrainman commented 8 years ago

Google Nexus 5 Android 5.1

jjobes commented 8 years ago

I just reproduced it on an emulator and I see what you mean. Let me take a closer look at this and I'll report back later.

jjobes commented 8 years ago

Okay, looks good to me! Did you want to submit a PR or do you just want me to push the changes and give you credit for it in the Changelog?

alexrainman commented 8 years ago

Just include the fix my friend. The credit is all yours for this amazing library. I migrated it to C# and im using it in Xamarin :)

jjobes commented 8 years ago

Okay, will do! I'm glad you find it useful :)

alexrainman commented 8 years ago

More than useful. I will include it in a free cross platform component for Xamarin.Forms and of course, give u the credit ;)

jjobes commented 8 years ago

Wow, that sounds great! Best of luck on your project!

alexrainman commented 8 years ago

Cheers for u 2!