-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from daisuke-nomura/master
reverse layout
- Loading branch information
Showing
5 changed files
with
204 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...c/main/java/com/lsjwzh/widget/recyclerviewpagerdeomo/ReverseSingleFlingPagerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.lsjwzh.widget.recyclerviewpagerdeomo; | ||
|
||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager; | ||
|
||
public class ReverseSingleFlingPagerActivity extends SingleFlingPagerActivity { | ||
@Override | ||
protected void initViewPager() { | ||
mRecyclerView = (RecyclerViewPager)findViewById(R.id.viewpager); | ||
LinearLayoutManager layout = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, | ||
true); | ||
mRecyclerView.setLayoutManager(layout); | ||
mRecyclerView.setAdapter(new LayoutAdapter(this, mRecyclerView)); | ||
mRecyclerView.setHasFixedSize(true); | ||
mRecyclerView.setLongClickable(true); | ||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | ||
@Override | ||
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { | ||
// updateState(scrollState); | ||
} | ||
|
||
@Override | ||
public void onScrolled(RecyclerView recyclerView, int i, int i2) { | ||
// mPositionText.setText("First: " + mRecyclerViewPager.getFirstVisiblePosition()); | ||
int childCount = mRecyclerView.getChildCount(); | ||
int width = mRecyclerView.getChildAt(0).getWidth(); | ||
int padding = (mRecyclerView.getWidth() - width) / 2; | ||
// mCountText.setText("Count: " + childCount); | ||
|
||
for (int j = 0; j < childCount; j++) { | ||
View v = recyclerView.getChildAt(j); | ||
//往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小 | ||
float rate = 0; | ||
; | ||
if (v.getLeft() <= padding) { | ||
if (v.getLeft() >= padding - v.getWidth()) { | ||
rate = (padding - v.getLeft()) * 1f / v.getWidth(); | ||
} else { | ||
rate = 1; | ||
} | ||
v.setScaleY(1 - rate * 0.1f); | ||
v.setScaleX(1 - rate * 0.1f); | ||
|
||
} else { | ||
//往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小 | ||
if (v.getLeft() <= recyclerView.getWidth() - padding) { | ||
rate = (recyclerView.getWidth() - padding - v.getLeft()) * 1f / v.getWidth(); | ||
} | ||
v.setScaleY(0.9f + rate * 0.1f); | ||
v.setScaleX(0.9f + rate * 0.1f); | ||
} | ||
} | ||
} | ||
}); | ||
mRecyclerView.addOnPageChangedListener(new RecyclerViewPager.OnPageChangedListener() { | ||
@Override | ||
public void OnPageChanged(int oldPosition, int newPosition) { | ||
Log.d("test", "oldPosition:" + oldPosition + " newPosition:" + newPosition); | ||
} | ||
}); | ||
|
||
mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { | ||
@Override | ||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { | ||
if (mRecyclerView.getChildCount() < 3) { | ||
if (mRecyclerView.getChildAt(1) != null) { | ||
if (mRecyclerView.getCurrentPosition() == 0) { | ||
View v1 = mRecyclerView.getChildAt(1); | ||
v1.setScaleY(0.9f); | ||
v1.setScaleX(0.9f); | ||
} else { | ||
View v1 = mRecyclerView.getChildAt(0); | ||
v1.setScaleY(0.9f); | ||
v1.setScaleX(0.9f); | ||
} | ||
} | ||
} else { | ||
if (mRecyclerView.getChildAt(0) != null) { | ||
View v0 = mRecyclerView.getChildAt(0); | ||
v0.setScaleY(0.9f); | ||
v0.setScaleX(0.9f); | ||
} | ||
if (mRecyclerView.getChildAt(2) != null) { | ||
View v2 = mRecyclerView.getChildAt(2); | ||
v2.setScaleY(0.9f); | ||
v2.setScaleX(0.9f); | ||
} | ||
} | ||
|
||
} | ||
}); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/lsjwzh/widget/recyclerviewpagerdeomo/ReverseVerticalPagerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.lsjwzh.widget.recyclerviewpagerdeomo; | ||
|
||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
import com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager; | ||
|
||
public class ReverseVerticalPagerActivity extends VerticalPagerActivity { | ||
@Override | ||
protected void initViewPager() { | ||
mRecyclerView = (RecyclerViewPager) findViewById(R.id.viewpager); | ||
|
||
LinearLayoutManager layout = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, | ||
true); | ||
mRecyclerView.setTriggerOffset(0.15f); | ||
mRecyclerView.setFlingFactor(0.25f); | ||
mRecyclerView.setLayoutManager(layout); | ||
mRecyclerView.setAdapter(new LayoutAdapter(this, mRecyclerView)); | ||
mRecyclerView.setHasFixedSize(true); | ||
mRecyclerView.setLongClickable(true); | ||
|
||
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { | ||
@Override | ||
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { | ||
|
||
} | ||
|
||
@Override | ||
public void onScrolled(RecyclerView recyclerView, int i, int i2) { | ||
// mPositionText.setText("First: " + mRecyclerViewPager.getFirstVisiblePosition()); | ||
int childCount = mRecyclerView.getChildCount(); | ||
int width = mRecyclerView.getChildAt(0).getWidth(); | ||
int padding = (mRecyclerView.getWidth() - width) / 2; | ||
|
||
for (int j = 0; j < childCount; j++) { | ||
View v = recyclerView.getChildAt(j); | ||
//往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小 | ||
float rate = 0; | ||
if (v.getLeft() <= padding) { | ||
if (v.getLeft() >= padding - v.getWidth()) { | ||
rate = (padding - v.getLeft()) * 1f / v.getWidth(); | ||
} else { | ||
rate = 1; | ||
} | ||
v.setScaleY(1 - rate * 0.1f); | ||
} else { | ||
//往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小 | ||
if (v.getLeft() <= recyclerView.getWidth() - padding) { | ||
rate = (recyclerView.getWidth() - padding - v.getLeft()) * 1f / v.getWidth(); | ||
} | ||
v.setScaleY(0.9f + rate * 0.1f); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters