B4A Library AHViewPager library - Sliding panels now perfect

This library is a B4A implementation of the ViewPager object provided by the compatibility class from google. With this library it is possible to add sliding panels to your apps.

AHPageContainer - This object is a container for the pages of the AHViewPager. You should add Panels to this object.

AHViewPager - This is the main object which provides the sliding panels.

All the Tabs objects are deprecated now. You can use them but I don't enhance them anymore. For nice looking Tabs please use the DSTabLayout object of the DesignSupport library.
Alternatively you can use the TabStripViewPager.


Installation:
  • From V3.00 on the library requires B4A 6.0 or later.
  • This library depends on the Android Support library so you need to install the Android Support repository in the Extras section with SDK Manager.
  • Copy the AHViewPager.xml and AHViewPager.jar files to your additional libraries folder.
Example project:

For an example project for this library see the Design Support Library.


Version History:

1.00:
- initial version

1.01:
- Added AHViewPagerFixedTabs object for a fixed tab indicator
- Fixed a bug that it was impossible to get the canvas of a panel which was added to the container (It was impossible to display charts on a page)
- Example for AHViewPagerFixedTabs tab indicator

1.02: (Never released)
- Fixes problem with tab height (Line is now always on the bottom)

1.03:
- Fixes problem with Line sometimes not updating correctly on Android 4.0+
- Fix UppercaseTitle property

2.0:
- Complete Rewrite of the Swipey tabs code to fix some bugs with newer android versions.

2.01:
- New property for the AHViewPager object: PagingEnabled - Enables or disables paging for the ViewPager.

2.02:
- New events PageScrolled and PageScrollStateChanged (with SCROLLSTATE constants)
See post 227 for details

2.20:
- Use raiseEventfromUI() in most events
- New SupportTabs object
- New SupportTitles object
- Support for Designer (as a Custom View)
- some minor internal changes and bug fixes

2.21:
- Use raiseEvent() for PageCreated and PageDestroyed event again to prevent double UI refreshes
- Added @RaiseSynchronousEvents annotation to GotoPage() (to make it better compatible with rapid debugger.

3.00:
- Support for Designer Custom Properties.
- Uses maven repository to access support library. (B4A 6.0 or later required)

Attention: V2.20 has an API change which makes the ViewPager incompatible with older versions. The AHPageContainer parameter is removed from the Initialize() method. Initialize2() has the old signature. If you use Initialize() (or add the View to the Designer as a custom view) then you have to set the container object with ViewPager.PageContainer = <YourContainer>

The examples use the old Initialize method, so they are broken. I was too lazy to fix them because I recommend the tab indicator from the Design Support library for a nice looking Material Design app.
 

Attachments

  • screenshot-1336034831196.png
    10.1 KB · Views: 8,306
  • screenshot-1336034966953.png
    9.9 KB · Views: 7,570
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,546
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,498
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
Without reading all 15 pages, I want to ask a question:
I want to use AHViewPager to display an ebook with more than 300 pages. I know we can load all pages when it first run but it's too slow and/or it will be crashed because low memory. Is it possible to load only 3 pages: Previous page, Current page, Next page. When user is reading Current page, only the Previous and Next page will be load. Is there any sample code to do that? Sorry for my laziness
 

ernschd

Active Member
Licensed User
Longtime User
In my opinion there are just 3 pages in memory. When the scrolling event fires, one page will be destroyed and the new one is loading into memory.
 

susu

Well-Known Member
Licensed User
Longtime User
In my opinion there are just 3 pages in memory. When the scrolling event fires, one page will be destroyed and the new one is loading into memory.

I want to ask how to execute it? I tried to load all 300 pages when it runs first time and it takes to long.
 

ernschd

Active Member
Licensed User
Longtime User
How do you get the content of your ebook? Is it stored in a file or in a database?
Maybe you could load just the needed 3 pages (current, previous, next) into memory...
 

susu

Well-Known Member
Licensed User
Longtime User
The content is in a database. I created a small app before, it's only 100 pages but it took too long to load at first run. Now with 300 pages I can't imagine how long it will take to finish loading. So I ask about another way to do. And I'm so lazy to read all 15 pages of this thread.
 

ernschd

Active Member
Licensed User
Longtime User
You could do a database query to get 3 pages. In the Pager_PageChanged-Event you get the actual position, which you can use for the next query:
B4X:
SELECT * FROM TABLE LIMIT X,Y
With this you have just 3 pages in memory.
 

luke2012

Well-Known Member
Licensed User
Longtime User

My compliments! Very good work !
I'm using this library with satisfaction!
 

gmartano68

New Member
Licensed User
Longtime User
Hi, i'm tryng AHViewer 2.02 .. I download library and put "xml" and "jar" AHV under B4 libraries plus "android-support-v4"

but when I compile B4 give me following error:


Any idea what's my problem? thnks, giovanni
 

PaulD

Member
Licensed User
Longtime User
I started my project building off of the AHViewPagerExample1_0.zip and it works GREAT... however as my project grew.. I needed to simply things... so I used NJDude's example... much simpler way to use the pager...

The problem that I am having is that I wanted to keep the GoToPage button on the bottom... but I cannot get the panels to re-size to fit the container....

I figure the secret is in this line of code... but I have changed everything I can think of and nothing seems to make the panel shorter...

Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height -35dip -2dip)
or
Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height -44dip,-35dip -2dip)

The size settings from the first example (AHViewPagerExample) is the second line of code... so you would think it would work ... but no


HELP! Please!
 

klaus

Expert
Licensed User
Longtime User
You set the Top property to 35dip + 2dip and the Height to Activity.Height - 35dip - 2dip.
This means that the bottom of the pager is at the bottom of the screen !
Try this:
Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height -35dip -2dip - Button.Height - 4dip)
You shoud adapt these values.
 

corwin42

Expert
Licensed User
Longtime User
Hi, i'm tryng AHViewer 2.02 .. I download library and put "xml" and "jar" AHV under B4 libraries plus "android-support-v4"

but when I compile B4 give me following error:



Any idea what's my problem? thnks, giovanni

I guess your support library is too old.
 

PaulD

Member
Licensed User
Longtime User

Thank for your response Klaus... Here is the line with the proper var

Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height -35dip -2dip - Button1.Height - 2dip)

and you are correct, the bottom of the pager is at the bottom of the screen... unfortunately adding the button1 reference did not work... any other thoughts?
 

PaulD

Member
Licensed User
Longtime User
You need to replace Button1 by the name of your button !

button1 is the name of my button...

BTW: adding
Log(pager.Height)
Log( Activity.Height -48dip-35dip -2dip - Button1.Height - 2dip)

Both equal 572

Even stranger is, when I remove the button1 and it's container, the pager panels are still full screen size, just pushed down the 35dip+2dip of the tabs and line... so the panels actually run off the screen

here is my full project on pastebin... http://pastebin.com/EVs7dpir
 

klaus

Expert
Licensed User
Longtime User
In your code you have:
Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height-48dip-35dip-2dip - Button1.Height - 2dip)
This is not what I suggested you, you have -48dip more.
With this line it works:
Activity.AddView(pager, 0, 35dip + 2dip, Activity.Width, Activity.Height - 35dip - 2dip - Button1.Height - 6dip)
In your DesignerScripts I found several lines like Lab_bizname.Left - 10%x
It should be Lab_bizname.Left = 10%x
Most layouts go bejond the bottom of the container panel.
I changed a bit the rep layout, but it's up to you to change it to your requirements.
You should reconsider all the layouts.
If you set all properties with %x and %y values you don't need AutoScale.
In the coupon layout you set couponbg.SetTopAndBottom(0, 100%y), the image with a height of 100%y will of course go below the bottom of the container panel.

Attached the modified project.
 

Attachments

  • RTV_Order_v0.7_1.zip
    162.2 KB · Views: 248

PaulD

Member
Licensed User
Longtime User


THANK YOU!! I am still learning all of the layout stuff.. and thought I was following the tutorial correctly... I see that I still have much to learn! Thanks for the help!!
 

john mad doe

Member
Licensed User
Longtime User
Hello

Is there a way to block the lateral scrolling ?

I use AHViewPager (thank you very much for this library) and I'm looking for a way to forbid the lateral movement to change pages; I want to force the user to use the tabs on the top of the pages.

Why this need: when a button is held on a page, if the user does a little , unwanted, movement of scrolling, we never get the information when the button is released. For my application I need to know when the button is released to achieve the action started when the button was held.


John
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…