I have the following code that make the ListView appears like a Vertical Gallery
public class VerticalGallery extends ListView {
private View currentDisplayingView;
private int currentPosition;
public VerticalGallery(Context context, List<Page> pages) {
super(context);
setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
currentDisplayingView = view;
currentPosition = position;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
setAdapter(new PageAdapter(context, pages));
setCacheColorHint(Color.TRANSPARENT);
}
public boolean onTouchEvent(MotionEvent evt) {
if (currentDisplayingView != null && currentDisplayingView.onTouchEvent(evt))
return true;
PageAdapter adapter = (PageAdapter) getAdapter();
if (currentPosition == adapter.list.size() - 1)
return false;
// TODO: Handle events and swipe somewhere
return super.onTouchEvent(evt);
}
public class PageAdapter extends BaseAdapter {
private Context context;
private List<Page> list;
public PageAdapter(Context c, List<Page> pages) {
context = c;
list = pages;
}
public int getCount() {
return list.size();
}
public Page getItem(int position) {
return list.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = getItem(position).generateView(context);
view.setLayoutParams(new ListView.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
return view;
}
}
}
But there's some behaviors that I need to simulate also:
- Centralize a View: When a new view come, I need to centralize it on my display.
- Fire
onItemSelected
events: I need those cause I dispatch events to the current view, and let theListView
scroll only when the currentView returns false on a touchEvent, I don't need exactly the ItemSelected events, this can be something similar. - And another question is, if the user swipe up, I should only translate one view (not several according to the speed of the gesture).
Any component that will let me do that will be a usefull answer also.
EDIT: Actually, I solved this problem with this solution Using Animation to swipe views but I'll keep this question open.