Multipage layout

Put your problem here if it does not fit any of the other categories.

Multipage layout

Postby aetmos » Mon Jan 28, 2008 9:32 pm

Hi All,

I'm trying to make an activity that has a multipage layout with previous/next buttons, etc. I know I could make a separate activity for each page, but that seems like a pain. After much experimentation, the best I can come up with is that I can use ViewAnimator to do what I want...however, I'm curious if anybody has any better ideas, especially since ViewAnimator doesn't have a showPrevious() method for some odd reason. Maybe I'm completely overlooking something obvious, as this seems like a pretty basic thing to want to do.

Here's what I'm doing:
Code: Select all
        //get the ViewAnimator from the XML
        va = (ViewAnimator)findViewById(R.id.view_animator);

        //demo of how to show next page
        va.showNext();

        //there's no show previous page function...I wonder why...
        //...

        //go back to page 0
        va.setDisplayedChild(0);


I did try PageTurner, but couldn't get it to work right. All of the children were displayed at the same time, so I could see page 2 beneath page 1. I also saw some mention on the Google dev group that PageTurner is being removed from the SDK in the next version. I thought of using ViewGroup too, but haven't really been able to find much in the way of an example of how to use ViewGroup, or even if it's suited to this task.

Anyway, I'd really appreciate some input from any of you.

Thanks,
Tom
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Top

Postby aetmos » Tue Jan 29, 2008 5:48 am

It just occurred to me that my problem is easily solved. I just have to call SetContentView() again when next/previous is pressed, and send it the appropriate layout for whatever page I'm going to.

Tom
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Postby cabernet1976 » Fri Feb 01, 2008 5:29 am

Hi aetmos,
ViewAnimator interest me so much. My question is: how to define ViewAnimator's layout? like the following?
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ViewAnimator ...>
  2.  
  3.     <View id="@+id/view0"
  4.  
  5.        ... />
  6.  
  7.  
  8.  
  9.     <View id="@+id/view2"
  10.  
  11.        ... />
  12.  
  13. </ViewAnimator>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby aetmos » Fri Feb 01, 2008 5:50 am

cabernet1976 wrote:Hi aetmos,
ViewAnimator interest me so much. My question is: how to define ViewAnimator's layout? like the following?
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ViewAnimator ...>
  2.     <View id="@+id/view0"
  3.        ... />
  4.  
  5.     <View id="@+id/view2"
  6.        ... />
  7. </ViewAnimator>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Yeah, basically. That seems to work for me. This is more or less what I was trying to do with it:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ViewAnimator id="@+id/view_animator" xmlns:android="http://schemas.android.com/apk/res/android"
  2.                         android:layout_width="wrap_content"
  3.                         android:layout_height="fill_parent">
  4.                  
  5.              
  6.  
  7. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" id="@+id/text"
  8.    android:layout_width="fill_parent" android:layout_height="fill_parent"
  9.    android:gravity="top" android:textAlign="center"
  10.    
  11.         android:paddingLeft="10px"
  12.         android:paddingTop="10px"
  13.         android:paddingRight="10px"
  14.         android:paddingBottom="10px"
  15.    
  16.    android:verticalScrollbarTrack="@drawable/scrollbar_vertical_track"
  17.    android:verticalScrollbarThumb="@drawable/scrollbar_vertical_thumb"
  18.    android:scrollbarFadeDuration="1000"
  19.    android:scrollbarSize="12dip">
  20.      <LinearLayout
  21.        android:orientation="vertical"
  22.        android:layout_width="fill_parent"
  23.        android:layout_height="wrap_content">
  24.  
  25.         <TextView
  26.                 android:normalTextColor="#000000"
  27.            android:layout_width="fill_parent"
  28.            android:layout_height="wrap_content"
  29.            android:text="@string/survey_page_1"/>
  30.      </LinearLayout>
  31. </ScrollView>
  32.                  
  33.            
  34.  
  35. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" id="@+id/text2"
  36.    android:layout_width="fill_parent" android:layout_height="fill_parent"
  37.    android:gravity="top" android:textAlign="center"
  38.    
  39.         android:paddingLeft="10px"
  40.         android:paddingTop="10px"
  41.         android:paddingRight="10px"
  42.         android:paddingBottom="10px"
  43.    
  44.    android:verticalScrollbarTrack="@drawable/scrollbar_vertical_track"
  45.    android:verticalScrollbarThumb="@drawable/scrollbar_vertical_thumb"
  46.    android:scrollbarFadeDuration="1000"
  47.    android:scrollbarSize="12dip">
  48.      <LinearLayout
  49.        android:orientation="vertical"
  50.        android:layout_width="fill_parent"
  51.        android:layout_height="wrap_content">
  52.  
  53.         <TextView
  54.                 android:normalTextColor="#000000"
  55.            android:layout_width="fill_parent"
  56.            android:layout_height="wrap_content"
  57.            android:text="@string/survey_page_2"/>
  58.      </LinearLayout>
  59. </ScrollView>
  60.                  
  61.  
  62. </ViewAnimator>
Parsed in 0.007 seconds, using GeSHi 1.0.8.4


Then in the code:

Code: Select all
   private ViewAnimator va;

        //get the ViewAnimator from the XML
        va = (ViewAnimator)findViewById(R.id.view_animator);

        //demo of how to show next page
        va.showNext();

        //there's no show previous page function...I wonder why...
        //...

        //go back to page 0
        va.setDisplayedChild(0);


It worked fine, but then I discovered I didn't really need it.
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Postby cabernet1976 » Fri Feb 01, 2008 7:14 am

Thanks :!:

I think your layout is not large enough to need two pages, so you forget this solution, right? :D
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby aetmos » Fri Feb 01, 2008 7:44 am

cabernet1976 wrote:I think your layout is not large enough to need two pages, so you forget this solution, right? :D


Well, I need more like 10 pages...but I think I can do everything I need with SetContentView() rather than using a ViewAnimator.
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Top

Postby cabernet1976 » Fri Feb 01, 2008 1:28 pm

cool :wink:
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 22 guests