Android : Paging a view with sliding left or right
I have a problem achiving a sertant effect in a app i am currently working on. The senario is something like this
On my first activity i display a list, and once a item is clicked i display a new activity that holds more details about the item.
Now i want to implement pageing on the detailed page so the user can slide 开发者_开发技巧left or right and gets the next or previusly item displayed without having to go back to the list a select.
i got a adapter for the items so it is no biggy getting the information about what item is shown and what the "siblings are"
i have been playing around with the view flipper but as far as i can see it needs the "views" rendered in the stumic of the viewflipper and i dont dare render 300 items out onCreate. any tips on using 3 views and populate em onCreate??
i have called the same activity with and animation so it slides in plus and intent telling what data to show, but it must be poor preformance to do that.
Any ideas ?
if u want to see just that animation/function i want. Tjek out google latitude pageing on u friends detailed page.
//thx in advanced
I've implemented the same behavior using ViewFlipper
with loading the Views on demand.
Here is a snapshot of what I was doing. It's not exactly the same as you wanted, but you can follow the same approach.
/**
* starts a new activity.
* @param activityToStart the activity class.
*/
public static void startActivity(Class<?> activityToStart) {
String name = activityToStart.getName();
while (history.contains(name)) {
name += "1";
}
View view = activity.getLocalActivityManager().startActivity(name,
new Intent(activity, activityToStart)).getDecorView();
history.add(name);
addView(view, name);
}
public void addView(View newView, String name) {
// add its name to the history.
history.add(name);
// change the view.
flipper.addView(newView);
if(history.size() != 1) {
flipper.setInAnimation(inFromUpAnimation());
View oldView = getActivityAt(history.size() - 2);
flipper.setOutAnimation(outFromBottomAnimation());
flipper.showNext();
}
}
private void back() {
if(history.size() > 1) {
View oldView = getActivityAt(history.size() - 1);
flipper.setInAnimation(inFromBottomAnimation());
setRemoveAnimation(oldView, outToUpAnimation(), history.remove(history.size() - 1));
flipper.showPrevious();
} else {
finish();
}
}
Here I've 3 functions (To start a new activity in your case you might change it to inflate the view if you want, the second that add the view, the third to remove the view when the user hit back).
Hope this helps!
An alternative solution is to use the new ViewPager
component from the Android compatibility package.
精彩评论