Comments (1)
`public class PickerLayoutManager extends LinearLayoutManager {
private float scaleDownBy = 0.66f;
private float scaleDownDistance = 0.9f;
private boolean changeAlpha = true;
private onScrollStopListener onScrollStopListener;
public PickerLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
super.onLayoutChildren(recycler, state);
int orientation = getOrientation();
if (orientation == HORIZONTAL) {
scaleDownViewHorizontal();
} else {
scaleDownViewVertical();
}
}
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
int orientation = getOrientation();
if (orientation == HORIZONTAL) {
int scrolled = super.scrollHorizontallyBy(dx, recycler, state);
scaleDownViewHorizontal();
return scrolled;
} else return 0;
}
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
int orientation = getOrientation();
if (orientation == VERTICAL) {
int scrolled = super.scrollVerticallyBy(dy, recycler, state);
scaleDownViewVertical();
return scrolled;
} else return 0;
}
private void scaleDownViewHorizontal() {
float mid = getWidth() / 2.0f;
float unitScaleDownDist = scaleDownDistance * mid;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
float childMid = (getDecoratedLeft(child) + getDecoratedRight(child)) / 2.0f;
float scale = 1.0f + (-1 * scaleDownBy) * (Math.min(unitScaleDownDist, Math.abs(mid - childMid))) / unitScaleDownDist;
child.setScaleX(scale);
child.setScaleY(scale);
if (changeAlpha) {
child.setAlpha(scale);
}
}
}
private void scaleDownViewVertical() {
float mid = getHeight() / 2.0f;
float unitScaleDownDist = scaleDownDistance * mid;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
float childMid = (getDecoratedTop(child) + getDecoratedBottom(child)) / 2.0f;
float scale = 1.0f + (-1 * scaleDownBy) * (Math.min(unitScaleDownDist, Math.abs(mid - childMid))) / unitScaleDownDist;
child.setScaleX(scale);
child.setScaleY(scale);
if (changeAlpha) {
child.setAlpha(scale);
}
}
}
@Override
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);
if (state == 0) {
if (onScrollStopListener != null) {
int selected = 0;
float lastHeight = 0f;
for (int i = 0; i < getChildCount(); i++) {
if (lastHeight < getChildAt(i).getScaleY()) {
lastHeight = getChildAt(i).getScaleY();
selected = i;
}
}
onScrollStopListener.selectedView(getChildAt(selected));
}
}
}
public float getScaleDownBy() {
return scaleDownBy;
}
public void setScaleDownBy(float scaleDownBy) {
this.scaleDownBy = scaleDownBy;
}
public float getScaleDownDistance() {
return scaleDownDistance;
}
public void setScaleDownDistance(float scaleDownDistance) {
this.scaleDownDistance = scaleDownDistance;
}
public boolean isChangeAlpha() {
return changeAlpha;
}
public void setChangeAlpha(boolean changeAlpha) {
this.changeAlpha = changeAlpha;
}
public void setOnScrollStopListener(onScrollStopListener onScrollStopListener) {
this.onScrollStopListener = onScrollStopListener;
}
public interface onScrollStopListener {
public void selectedView(View view);
}
}
`
and change the layout file to
`
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:clipToPadding="false"
android:paddingBottom="183dp"
android:paddingTop="183dp" />
`
from horizontalpicker.
Related Issues (14)
- How to change number visible offset elements
- How to set initial selected item to first item and final item to last item in the list?
- When click item call setOnScrollStopListener twice
- vertical functionality
- The first image does not scale
- Publish this library in MavenCenter
- Not able to add gradle dependency HOT 3
- scaledownby, scaledowndistance not work at the start app. HOT 3
- License issue
- Set initial selected item or view HOT 12
- How Can I manage the setOnScrollChangeListener(new PickerLayoutManger.onScrollStopListner())
- not accurate in the Toast middle term HOT 1
- How can I use it on landscape HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from horizontalpicker.