Skip to content

Commit 749e238

Browse files
Merge pull request #156 from Omega-R/add_padding_to_view_pager
add padding treatment
2 parents 24f689b + fc93352 commit 749e238

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

app/src/main/res/layout/activity_view_pager.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
android:layout_width="match_parent"
1818
android:layout_height="match_parent"
1919
android:orientation="horizontal"
20+
android:paddingLeft="10dp"
21+
android:clipChildren="false"
22+
android:clipToPadding="false"
2023
app:autoScrollEnabled="true"
21-
app:autoScrollInterval="2500"
2224
app:pageSize="1"
2325
app:transformer="RotateUpTransformer"
2426
app:infinite="true"/>
27+
<!-- app:autoScrollInterval="2500"-->
2528

2629
</LinearLayout>

app/src/main/res/layout/item_image.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ImageView
1010
android:id="@+id/imageview"
1111
android:layout_height="250dp"
12-
android:layout_width="match_parent"
12+
android:layout_width="wrap_content"
1313
android:scaleType="fitXY"
1414
tools:src="@drawable/image_1"/>
1515

omegarecyclerview/src/main/java/com/omega_r/libs/omegarecyclerview/viewpager/ViewPagerLayoutManager.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ private View getMeasuredChildForAdapterPosition(int position, RecyclerView.Recyc
190190
View view = recycler.getViewForPosition(calculateRealPosition(position));
191191
addView(view);
192192

193-
int width = getWidth();
194-
int height = getHeight();
193+
int width = getWidth() - getPaddingLeft() - getPaddingRight();
194+
int height = getHeight() - getPaddingTop() - getPaddingBottom();
195195
switch (mOrientation) {
196196
case HORIZONTAL:
197197
width *= mPageSize;
@@ -251,15 +251,22 @@ private int getMeasuredHeightWithMargin(View child) {
251251
}
252252

253253
private void updateRecyclerDimensions() {
254-
mRecyclerCenterPoint.set(getWidth() / 2, getHeight() / 2);
254+
mRecyclerCenterPoint.set(
255+
(getWidth() + getPaddingLeft() - getPaddingRight()) / 2,
256+
(getHeight() + getPaddingTop() - getPaddingBottom()) / 2
257+
);
255258
}
256259

257260
private void fill(RecyclerView.Recycler recycler) {
258261
cacheAndDetachAttachedViews();
259262

260263
mOrientationHelper.setCurrentViewCenter(mRecyclerCenterPoint, mScrolled, mCurrentViewCenterPoint);
261264

262-
final int endBound = mOrientationHelper.getViewEnd(getWidth(), getHeight());
265+
final int endBound = getClipToPadding() ?
266+
mOrientationHelper.getViewEnd(
267+
getWidth() - getPaddingRight(),
268+
getHeight() - getPaddingBottom())
269+
: mOrientationHelper.getViewEnd(getWidth(), getHeight());
263270

264271
if (mScrolled >= 0) {
265272
layoutViews(recycler, Direction.START, endBound); //Layout items before the current item

0 commit comments

Comments
 (0)