Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4android > Basic4android Getting started & Tutorials
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Basic4android Getting started & Tutorials Android development starts here. Please do not post questions in this sub-forum.

Android SlidingPanels - Simple way to create sliding layouts

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-13-2011, 03:27 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Thumbs up Android SlidingPanels - Simple way to create sliding layouts

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.



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.
Attached Files
File Type: zip SlidingPanels.zip (6.9 KB, 758 views)
Reply With Quote
  #2 (permalink)  
Old 03-13-2011, 04:54 PM
Basic4ppc Expert
 
Join Date: May 2008
Posts: 550
Default

It will be great if we can slide by touching screen directly
__________________
I'm not good at English, please understand. Thank you.
Reply With Quote
  #3 (permalink)  
Old 03-15-2011, 06:48 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

That's not hard at all.
Just add the following code to the Main activity (replace the existing Sub Globals):
Code:
Sub Globals
    
Dim sd As SlidingData 'The object that holds the for SlidingPanels
    Dim btnLeft, btnRight As Button
    
Dim startX, startY As Float '<-new global variables
End Sub

Sub Panels_Touch (Action As Int, X As Float, Y As Float)
    
Select Action
        
Case Activity.ACTION_DOWN
            startX = X
            startY = Y
        
Case Activity.ACTION_UP
            
If Abs(y - startY) > 20%y Then Return
            
If X - startX > 30%x AND btnRight.Enabled = True Then 
                ChangePanel(
False)
            
Else If startX - x > 30%x AND btnLeft.Enabled = True Then
                ChangePanel(
True)
            
End If
    
End Select
End Sub
Reply With Quote
  #4 (permalink)  
Old 03-15-2011, 10:07 PM
Basic4ppc Expert
 
Join Date: May 2008
Posts: 550
Default

It's really smooth! Thanks Erel
__________________
I'm not good at English, please understand. Thank you.
Reply With Quote
  #5 (permalink)  
Old 03-16-2011, 10:09 AM
Senior Member
 
Join Date: Feb 2011
Posts: 106
Default

Thanks Erel..Nice.
Can the panel contains very long text and scrollable?
Reply With Quote
  #6 (permalink)  
Old 03-16-2011, 10:18 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Quote:
Can the panel contains very long text and scrollable?
Not sure how it is related to the sliding panels framework. However you can put an EditText on the panel. Set it to be a multiline EditText and set WordWrap to true.
Reply With Quote
  #7 (permalink)  
Old 06-18-2011, 02:28 PM
Senior Member
 
Join Date: Feb 2011
Posts: 106
Default

Erel:
I have created a menu of all panels in ListView, how can I link from ListView directly to panels number based on position of the ListView. eg. If I click on ListView position seven I want panel number seven to show. Thanks in advance.
Reply With Quote
  #8 (permalink)  
Old 06-19-2011, 08:35 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

I've updated the first post with a new version of SlidingPanels. It includes a JumpToPanel method that allows you to navigate to any panel. Press on the menu button to see an example.
Reply With Quote
  #9 (permalink)  
Old 06-19-2011, 10:42 AM
Junior Member
 
Join Date: May 2011
Posts: 26
Default

This is awesome! Fantastic work Erel!

cheers Waz
__________________
Please dont flame me because I am not as good as you.
Reply With Quote
  #10 (permalink)  
Old 06-20-2011, 09:43 AM
Senior Member
 
Join Date: Feb 2011
Posts: 106
Default

Thanks, Erel. Its work great!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone can help me design one simple Android Apps with Basic4android LouieChan Basic4android Updates and Questions 5 04-16-2012 12:32 AM
Simple way to create a scrollable panel? corwin42 Questions (Windows Mobile) 7 09-23-2011 11:24 AM
Just in time layouts stevel05 Basic4android Updates and Questions 4 02-06-2011 05:41 AM
layouts like settings Cor Basic4android Updates and Questions 1 11-16-2010 08:44 AM
change layouts Cor Basic4android Updates and Questions 1 11-16-2010 08:43 AM


All times are GMT. The time now is 10:34 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0