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.

Your support:
Creating libraries and wrappers for existing library projects is a lot of work. The use of this library is totally free and you even don't need to mention in your app that you use it.
But if you use this library in your projects and you think it is useful to you please consider to make a donation:

Thanks very much for your support.

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
    screenshot-1336034831196.png
    10.1 KB · Views: 8,074
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,329
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,335
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,240
Last edited:

BarryW

Active Member
Licensed User
Longtime User
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.

any sample for fixtab?
 

corwin42

Expert
Licensed User
Longtime User

woniol

Active Member
Licensed User
Longtime User
I'm currently working on a new feature of the DesignSupport library which will support the CoordinatorLayout and CollapsingToolbarLayout. With this new feature all your mentioned effects will be possible.
Hi,
Did You manage to make some progress on adding CoordinatorLayout and CollapsingToolbarLayout feature to the DesignSupport library?
 

corwin42

Expert
Licensed User
Longtime User
Hi,
Did You manage to make some progress on adding CoordinatorLayout and CollapsingToolbarLayout feature to the DesignSupport library?

Yes but it is still far away from stable and usable.
 

konradwalsh

Active Member
Licensed User
Longtime User
Hello
I have read every post on this thread and the design support thread. On the design support thread someone asks a similar question but they were told ot open a post here.. I dont see it


I am using the sample Navigation View

I amended the for loop[ to name the pages with my titles as such
B4X:
Dim titles(3) As String = Array As String ("Midweek", "Weekend", "Others")

    Dim p(3)  As Panel
    For i = 0 To 2
        'Create a panel for the page with a random color.
    
        p(i).Initialize("")
        p(i).Color = Colors.Gray
        Dim pageName As String
        pageName = titles(i)    
        PC.AddPage(p(i), pageName)    
        subMenu.AddWithGroup2(3, 100+i, 100+i, pageName, xml.GetDrawable("ic_bookmark_black_24dp"))
    Next


I want to load each panel with a layout file. But I want to be able to use scrollview.
This is what I am trying with:

B4X:
p(0).LoadLayout("midweekScoll")
    midweekScroll.Panel.LoadLayout("midweek")
    midweekScroll.Panel.Height = panContent.Top + panContent.Height
    midweekScroll.Panel.Width =  75%y

I see my midweek layout show up but I cant scoll up or down on it.

It seems that I somehow need to attach my scrollview to the ViewPager control..


please advise what I am doing wrong





edit: I somehow posted this is a different thread.. I deleted that thread and posted it here
 

konradwalsh

Active Member
Licensed User
Longtime User
Thanks for providing assistance.

panContent is a panel within the layout file midweek. as that panel is the full size of the layout, I wanted to have the scroll view match.

The thing is, I can see the layout, I just cant veritcally scroll.
 

konradwalsh

Active Member
Licensed User
Longtime User
ok, I have removed that line now to make sure and I still have this issue.

it now looks like this:
B4X:
p(0).LoadLayout("midweekScoll")
midweekScroll.Panel.LoadLayout("midweek")


what I believe I am doing here is loading a scroll view into the ViewPager Panel
and then loading my layout into the scrollview
 

konradwalsh

Active Member
Licensed User
Longtime User
OK.. so I went into my layout for midweekScroll. If I remove the anchor points and set it to top and left
I can now scroll both ways.. but it doesn't fill the page. And scrolls only half way down the content



maybe i need to use Addview instead of loading a layout file..
 

Attachments

  • 2017-02-02_13h11_04.png
    2017-02-02_13h11_04.png
    10.1 KB · Views: 253
Last edited:

konradwalsh

Active Member
Licensed User
Longtime User
And.... here is the solution:

B4X:
midweekScroll.Initialize(4500dip)
p(0).AddView(midweekScroll,1,1,100%x,4500)
  midweekScroll.Panel.LoadLayout("midweek")

seems you must use addview instead of the way I was doing it..

but raises a different problem for me..

Notice the HEIGHT of the scroll view and panel.. I have set these like this because setting p(0).height or VP.Height gives errors

java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.height' on a null object reference

ANy thoughts
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi, I try this amazing lib. But I have a question :
I read from a database the amount of panel a need to create, created dynamically
but I cant choose or does not knw how to delete and specific panel from de sliding group.

any one?

Thanks,

Victor
 

corwin42

Expert
Licensed User
Longtime User
I read from a database the amount of panel a need to create, created dynamically
but I cant choose or does not knw how to delete and specific panel from de sliding group.

B4X:
AHPageContainer.DeletePage()
 

corwin42

Expert
Licensed User
Longtime User
What about a bullet to idenfied that there is more panels to the left.
can be possible ?

There is no special view for this but you can create it very easily on your own. Just update the bullets in the PageChanged event.
 

Manuel Martinez

Member
Licensed User
Longtime User
Hi Victor,

I hope that help you.

As @corwin42 said, the color is updated in the PageChanged event, you can always change there size and position as you need.

I use AHviewPager(3.0) and DesignSupport(2.10) libraries
 

Attachments

  • bullets.pager.zip
    9 KB · Views: 300
Top