일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 안드로이드
- apk 다운사이징
- Magnify Anim
- ios framework
- SO 파일
- embedd
- Google V8 Engine
- Android
- 공인인증서 정보
- Push
- FlexiblePageView
- IMAGE
- PageControl
- 인증서 정보 뽑아내기
- so file
- apache
- Objective C
- appbarlayout
- Android NDK시스템
- java
- IOS10
- ios
- v8 engine xcode build
- V8 Engine
- sha1 convert hashkey
- 공인인증서 만료일
- apns
- android log dump
- JavaScript Engine
- Status Bar
Archives
- Today
- Total
caTea 블로그
AppBarLayout 부드럽게 스크롤 본문
반응형
어느 양키성님께서 만든 클래스
아주 부드럽게 작동한다
/**
* Created by achee7059 on 2017. 4. 14..
*
* 앱바 스크롤 부드럽게 하는 클래스
*/
public class FlingBehavior extends AppBarLayout.Behavior {
private static final String TAG = FlingBehavior.class.getName();
private static final int TOP_CHILD_FLING_THRESHOLD = 1;
private static final float OPTIMAL_FLING_VELOCITY = 3500;
private static final float MIN_FLING_VELOCITY = 20;
boolean shouldFling = false;
float flingVelocityY = 0;
public FlingBehavior() {
}
public FlingBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target,
int velocityX, int velocityY, int[] consumed) {
super.onNestedPreScroll(coordinatorLayout, child, target, velocityX, velocityY, consumed);
if (velocityY > MIN_FLING_VELOCITY) {
shouldFling = true;
flingVelocityY = velocityY;
} else {
shouldFling = false;
}
}
@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout abl, View target) {
super.onStopNestedScroll(coordinatorLayout, abl, target);
if (shouldFling) {
Log.d(TAG, "onNestedPreScroll: running nested fling, velocityY is " + flingVelocityY);
onNestedFling(coordinatorLayout, abl, target, 0, flingVelocityY, true);
}
}
@Override
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target,
float velocityX, float velocityY, boolean consumed) {
if (target instanceof RecyclerView && velocityY < 0) {
Log.d(TAG, "onNestedFling: target is recyclerView");
final RecyclerView recyclerView = (RecyclerView) target;
final View firstChild = recyclerView.getChildAt(0);
final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild);
consumed = childAdapterPosition > TOP_CHILD_FLING_THRESHOLD;
}
// prevent fling flickering when going up
if (target instanceof NestedScrollView && velocityY > 0) {
consumed = true;
}
if (Math.abs(velocityY) < OPTIMAL_FLING_VELOCITY) {
velocityY = OPTIMAL_FLING_VELOCITY * (velocityY < 0 ? -1 : 1);
}
Log.d(TAG, "onNestedFling: velocityY - " + velocityY + ", consumed - " + consumed);
return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed);
}
}
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/abl_recommend_detail"
app:layout_behavior="com.ubist.tourtainment.flag.utils.FlingBehavior">
mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (!shouldScroll)
mNestedScrollView.fullScroll(ScrollView.FOCUS_UP);
}
});
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
Log.e(TAG, "verticalOffset = " + Math.abs(verticalOffset));
Log.e(TAG, "appBarLayout.getTotalScrollRange = " + appBarLayout.getTotalScrollRange());
shouldScroll = Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange();
}
728x90
'android' 카테고리의 다른 글
android crash dump (0) | 2017.12.20 |
---|---|
android google map 좌표들을 이용해 스크린에 꽉차게 (0) | 2017.05.25 |
Magnify Anim View Pager (0) | 2017.03.13 |
android frame animation class (0) | 2017.02.22 |
android permission activity (0) | 2017.02.22 |