Bug 8532 - GetPageWidth not working as documented
Summary: GetPageWidth not working as documented
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-20 18:34 UTC by Pierce Boggan [MSFT]
Modified: 2012-11-26 11:52 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Support-4-Fragment-Pager.png (90.59 KB, image/png)
2012-11-20 22:33 UTC, Jonathan Pryor
Details
Support4-Fragment-Pager-GalaxyNexus.png (71.27 KB, image/png)
2012-11-20 22:36 UTC, Jonathan Pryor
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Pierce Boggan [MSFT] 2012-11-20 18:34:27 UTC
I'm trying to override the GetPageWidth method of the MyAdapter class (inherited from FragmentPagerAdapter) so that it returns 0.5 (50%, so that I can get two pages side by side within a single ViewPager).

Java Documentation: https://developer.android.com/reference/android/support/v4/view/PagerAdapter.html#getPageWidth(int)


public override float GetPageWidth(int p0)

{
//return base.GetPageWidth(p0);
//base.GetPageWidth(p0);
return (0.5f);
}

Attached is test case.
Comment 1 Pierce Boggan [MSFT] 2012-11-20 18:35:11 UTC
Created attachment 2980 [details]
Test case

Not up to date on all my Android stuff, be research indicates this should work.
Comment 2 Jonathan Pryor 2012-11-20 22:33:56 UTC
Created attachment 2982 [details]
Support-4-Fragment-Pager.png

is it possible that you only get your side-by-side behavior on tablets? Attached is a screenshot of your app running on my Nexus 10, and the Fragment/Pager demo does show side-by-side Fragments, each taking 50% of the screen.

What device are you running your app on?
Comment 3 Jonathan Pryor 2012-11-20 22:36:20 UTC
Created attachment 2983 [details]
Support4-Fragment-Pager-GalaxyNexus.png

For that matter, I get proper 50% side-by-side behavior on my Galaxy Nexus (Android 4.1.2). Perhaps I need to try an older device?
Comment 4 Samus Arin 2012-11-21 09:08:52 UTC
Hello Mr. Pryor, I'm the guy who filed the "bug". 

I'm running it on an Asus Tranformer TF700T, 10" screen.

I was wondering if maybe using the Fragments/ViewPager through
the Support4 library, instead of directly, has something to do with it ?

Is there a way to use Fragments/ViewPager without Support4, which I
believe is for backward compatibilty (with older versions of Android)
anyway, which I do not need (my target is 4 and up).
Comment 5 Samus Arin 2012-11-21 09:13:19 UTC
Pierece, you do not need to keep the test case private, if it helps matters, as it has no propietary code (its a direct example from github, published by Jonathan Pryor himself).
Comment 6 Samus Arin 2012-11-21 09:45:49 UTC
Pierece, you do not need to keep the test case private, if it helps matters, as it has no propietary code (its a direct example from github, published by Jonathan Pryor himself).
Comment 7 Jonathan Pryor 2012-11-21 09:48:01 UTC
Which Android version is the Asus Transformer running?

According to the specs page, it's running Android 4.0:
http://www.asus.com/Tablet/Transformer_Pad/ASUS_Transformer_Pad_Infinity_TF700T/#specifications

Would it be possible to get a screenshot of what you're seeing? You can do that through the `ddms` or `monitor` Android SDK programs.

> I was wondering if maybe using the Fragments/ViewPager through
> the Support4 library, instead of directly, has something to do with it ?

This doesn't make sense to me; the attached project is using Mono.Android.Support.V4.dll ("android-support-v4.jar"), and it works for me...

> my target is 4 and up

This needs more context. Do you mean API-4 (Android 1.6) and up? Or Android 4.0 (API 14) and up? There's a large difference there...

If you can target Android 4.0 and later (API 14+), then you don't need the support library, you can use the corresponding Android.App and related types instead. I don't know if this will work, but it would certainly be interesting to know the result.

Note that there some API incompatibilities between the Support types and the API-14 types, so some work will be needed to migrate between them.
Comment 8 Samus Arin 2012-11-21 12:18:20 UTC
> Which Android version is the Asus Transformer running?

4.0.3

> Would it be possible to get a screenshot of what you're seeing? You can do 
> that through the `ddms` or `monitor` Android SDK programs.

I'ts just a ViewPager Widget that takes of most of the screen, centered, and within the ViewPager is its contents: it displays one page at a time, where each page is a simple list. It pages ok and everything.

The GetPageWidth method is never even called (my log messages within it never fire).

>> I was wondering if maybe using the Fragments/ViewPager through
>> the Support4 library, instead of directly, has something to do with it ?

> This doesn't make sense to me; the attached project is using
> Mono.Android.Support.V4.dll ("android-support-v4.jar"), and it works for me...

You answered this below, stating:

"If you can target Android 4.0 and later (API 14+), then you don't need the
support library, you can use the corresponding Android.App and related types
instead. I don't know if this will work, but it would certainly be interesting
to know the result."

I will do this right now. Just to point out, if using Android 3.0 (API 11) and 
up and using "normal" fragments (not through support lib), then you need to derive from regular Activity (not FragmentActivity).

I'm confident this will work for me and report back with my findings.

>> my target is 4 and up

> This needs more context. Do you mean API-4 (Android 1.6) and up? Or Android 
> 4.0(API 14) and up? There's a large difference there...

Sorry, I mean Android 4.0 (API 14) and up.
Comment 10 Samus Arin 2012-11-21 13:02:24 UTC
Well its working now.  The only thing I did was I copied the android-support-v4.jar file from the \android-sdk\extras\android\support\v4 directory, where previously I just grabbed the first one I found in a file search of my hard drive (after closer look they are different sizes, and so not identical to the "official" sdk jar).

I guess while I got ya on the line, do you know why ViewPager exists exlusively in the 	android.support.v4 namespace (I couldn't find a ViewPager in Android.App or anywhere else !?).

It appears that all the classes associated with fragments are scattered between the support library and the regualar App library (some exits in both places, where other are exlusive) ?  Very confusing and frustrating.

Thank you for your help with this, Dan.
Comment 11 Samus Arin 2012-11-21 15:24:30 UTC
Here is my formal question about the "missing" FramePagerAdapter
Comment 13 Jonathan Pryor 2012-11-26 11:52:58 UTC
Looks like this isn't a bug in Mono for Android, as per Comment #10.