Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

android - Swipe half page in a ViewPager (from compatibility pack)

I am using a ViewPager with a PageAdapter (from the compatibility pack v4) to swipe among a horizontal list of boxes. The problem is that my second box from the first page is the first box in the second page (visually and conceptually). Something like this:

enter image description here

The way I am doing now it works. However, this becomes kinda weird because at the middle of the swipe there is a situation that the same box appears twice (like it is shown in the image).

There is a way to swipe only "half" page?

EDIT:

The boxes are an abstraction. In fact each box is a ListView and I create different pages just changing the adapter of each ListView.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Create one fragment per page
  2. Override getPageWidth() in PageAdapter to display more than one page

Code:

@Override
public float getPageWidth(int position) {
    float nbPages = 2; // You could display partial pages using a float value
    return (1 / nbPages);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...