6

I need to provide facility as shown in images.

enter image description here

Second View

In first view when there is viewpager at bottom. When user swap from right to left the first should replace by second. That I can do. But
My question is how to so half portion of next view at end of right side and and of left side.

i.e.'irst' of first view and 'Thir' of second view.

user861973
  • 787
  • 3
  • 11
  • 26

4 Answers4

6

You can use gallery here. Inside gallery for each items, set the layout params (width) to fit with your requirement.

Problem with gallery is that it does not rotate the items. Which means that once you reach the end of the list, you do not get first item.

But there is a trick to over come that too. All you need to do is to set the list count to very large number (INT_MAX) and in your adapter carefully return proper views by % calculation.

This will ensure that you will not reach end of list soon.

Chitranshu Asthana
  • 1,089
  • 8
  • 19
5

I'd suggest checking out the solution for the question Android ViewPager with previous and next pages visible?) - using a negative page margin (via ViewPager.setPageMargin) will allow you see multiple pages at a time (i.e., to the left and right of your current page).

Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • but problem is that we cannot put two viewpager in single activity or layout. – user861973 Sep 24 '12 at 10:26
  • @user861973 - ah, your post said 'there is viewpager at bottom', hence why I thought you were already using a ViewPager for the bottom scroll bar and not also for the main content. In that case, I might suggest using [ViewPagerIndicator](http://viewpagerindicator.com/) and specifically the [TabPageIndicator](https://github.com/JakeWharton/Android-ViewPagerIndicator/blob/master/library/src/com/viewpagerindicator/TabPageIndicator.java). In that case, you'd probably want to just use a negative margin in the layout itself to get the side tab images to only half show. – ianhanniballake Sep 26 '12 at 01:44
4

you should use HorizontalScrollView instead of gallery as it is deprecated from jellybeans version.

http://developer.android.com/reference/android/widget/Gallery.html

himanshu
  • 1,990
  • 3
  • 18
  • 36
2

Finally I found a solution to this. You are using TitlePageIndicator of the view pager indicator in your project. For achieving this effect you need to make few modification to the TitlePageIndicator class.
The idea is to shift the text on the left hand side toward left by an amount equal to half it's size(could be anything) and the text on the right hand side toward right by an amount equal to half it's size(could be anything).

For setting bounds to the texts on the left hand side clipViewOnTheLeft(...) method is used and for setting bounds to the text on the right hand side clipViewOnTheRight(...) method is used. Here you need to make these modifications.

Here is what you need to do:

/**
 * Set bounds for the right textView including clip padding.
 *
 * @param curViewBound
 *            current bounds.
 * @param curViewWidth
 *            width of the view.
 */
private void clipViewOnTheRight(RectF curViewBound, float curViewWidth, int right) {
    curViewBound.right = right - mClipPadding + curViewWidth/2;
    curViewBound.left = curViewBound.right - curViewWidth;
}

/**
 * Set bounds for the left textView including clip padding.
 *
 * @param curViewBound
 *            current bounds.
 * @param curViewWidth
 *            width of the view.
 */
private void clipViewOnTheLeft(RectF curViewBound, float curViewWidth, int left) {
    curViewBound.left = left + mClipPadding - curViewWidth/2;
    curViewBound.right = mClipPadding + curViewWidth;
}

You need to make these changes to the TitlePageIndicator.java file.

karn
  • 5,963
  • 3
  • 22
  • 29