-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathScrollViewFragment.java
More file actions
61 lines (45 loc) · 1.77 KB
/
Copy pathScrollViewFragment.java
File metadata and controls
61 lines (45 loc) · 1.77 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.rahul.bounce;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import com.rahul.bounce.library.BounceTouchListener;
public class ScrollViewFragment extends Fragment {
private ScrollView scrollView;
private View header;
public ScrollViewFragment() {
}
public static ScrollViewFragment newInstance() {
ScrollViewFragment fragment = new ScrollViewFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_scroll_view, container, false);
header = root.findViewById(R.id.header_image_view);
scrollView = (ScrollView) root.findViewById(R.id.scroll_view);
BounceTouchListener bounceTouchListener = BounceTouchListener.create(scrollView, R.id.content,
new BounceTouchListener.OnTranslateListener() {
@Override
public void onTranslate(float translation) {
if (translation > 0) {
float scale = ((2 * translation) / header.getMeasuredHeight()) + 1;
header.setScaleX(scale);
header.setScaleY(scale);
}
}
}
);
scrollView.setOnTouchListener(bounceTouchListener);
return root;
}
}