Android Tutorial Android SlidingPanels - Simple way to create sliding layouts

This is an old tutorial. There are now simpler and better ways to achieve this effect.

For example: https://www.b4x.com/android/forum/threads/tabstripviewpager-better-viewpager.63975/

Sliding layouts are cool.

Using the Animation library it is not difficult to animate single views and panels that hold other views.
The following code module and example project makes it even simpler to create a layout that is made of a number of panels. Whenever the current visible panel is changed, the current panel slides out and the new panel slides in.
As Panels can load layout files, you can create complex layouts by loading a layout file to each panel.

slidingpanels_1.png


The project is made of two components. The Main activity and the SlidingPanels code module.
You should add the SlidingPanels code module to your project and add a reference to the Animation library.

The main activity code is commented and explains the several integration points required.

Animations look much better on real devices than on the slow emulator.
Even if you are not interested in sliding layouts it is recommended to go over the code. It demonstrates the power of custom types which enable you to easily group many objects.
As code modules cannot hold references to Activity objects (like views), the calling activity passes the type with all the required data each time it calls a method (passing the data is done by passing a single pointer, there is no overhead here).

Questions and comments are always welcomed.
 

Attachments

  • SlidingPanels.zip
    6.9 KB · Views: 10,010
Last edited:

awama

Active Member
Licensed User
Longtime User
Array Index Out of Bounds error

I get an Array Index Out of Bounds error.

Update: No, I think it was a problem with another app with the same name. I modified the old example and broke it. I think the process was still in memory.

I also get an Array Index Out of Bounds error (line 29, slidingPanels_changepanel) whenever I resume the App AND the last state was Panel 0 ?!
 

awama

Active Member
Licensed User
Longtime User
Yes, I try it with the program attached to the first post?
If I start the App new after I pressed the home button on the phone while the "panel 0" is showing then I get an error..
 

buttons

Member
Licensed User
Longtime User
sliding panel with a list view

Hi. The sliding panels thing is great.

I have a problem, one of the layouts I am loading to one of the sliding panels comprises of a panel containing a listview. When I slide to this panel, and then onto the next, the list view is left behind, kind of like an overlay.
I removed it from the panel, and my other layouts work as expected.

Any ideas folks? Many thanks, Mark:confused:
 

buttons

Member
Licensed User
Longtime User
The layout file has a panel, Panel1 with the ListView on it (ie. Panel1 is parent item), and Activity is parent item for Panel1.
I have declared LstStats as ListView, initialised it LstStats.Initialize("LstStats"), and when I've added some items to it, I do:
Activity.AddView(LstStats, 0, 0, 100%x, 100%y)
 

buttons

Member
Licensed User
Longtime User
Aha, of course you are right, thankyou.

I had assumed that because the layout had LstStats on Panel1 that it would find its way there!
 

skcud

Member
Hey Guys, could someone please explain why this doesn't work on my system? I know there is something I haven't done, most likely to do with the libraries, I just can't figure it out.

I get a library reference error about the term 'slidingdata'.

I've checked 'animation' in the lib section and it is version 1.02. What is it that I haven't done/have done wrong?

Thanks :)
 

pluton

Active Member
Licensed User
Longtime User
Hey Guys, could someone please explain why this doesn't work on my system? I know there is something I haven't done, most likely to do with the libraries, I just can't figure it out.

I get a library reference error about the term 'slidingdata'.

I've checked 'animation' in the lib section and it is version 1.02. What is it that I haven't done/have done wrong?

Thanks :)

Did you forgot in project module SlidingPanels ???

slide.png
 

skcud

Member
Excellent, thank you. The app failed to load the module and I didn't even realise. Was because I also hadn't realised that I didn't unzip the package...was a long day...
Thanks for the help :)
 

Cdymock

Member
Licensed User
Longtime User
Sliding Panels With Scroll View Swipe Not Captured

Hi,

I am using the sliding panels code which is excellent.

I have added a scroll view to the panel, the scroll view scrolls up and down with a swipe however, I no longer get the ability to the slide the panel from left to right. I guess the scroll view is capturing and keeping the touch event is there anyway to get round this?

i have tried using Initialize2 for the scroll view and declaring an event and tried event_Touch to try and capture these but noting seems to come through.

Cheers

Chris
 
Last edited:
Top