Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make all ViewPager item center-aligned when PagerAdapter.getPageWidth() < 1f

Issue description: When PagerAdapter.getPageWidth() < 1f, the item shows at the left side.

My question I want the item to be at center or right side. So when scrolling left or right, all the items will be center-alignment. (ViewPager width = page width + 2*pageMargin)

like image 341
liangwang Avatar asked Aug 16 '13 00:08

liangwang


1 Answers

You can translate Canvas in drawChild method,like

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    canvas.save();
    canvas.translate(distance, 0);  // change any distance value you want
    boolean r = super.drawChild(canvas, child, drawingTime);
    canvas.restore();
    return r;
}
like image 139
Syan Law Avatar answered Sep 27 '22 18:09

Syan Law