blob: 052590e193fca19139d55c62f94763d937caba08 (
plain)
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
|
package moe.yuuta.flow.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
public class FlowPager extends ViewPager {
public FlowPager(@NonNull Context context) {
super(context);
}
public FlowPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
// Thanks to https://stackoverflow.com/a/20784791/6792243
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for(int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if(h > height) height = h;
}
if (height != 0) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
// Thanks to https://stackoverflow.com/a/13437997/6792243
@Override
public boolean onTouchEvent(MotionEvent event) {
return false;
}
// Thanks to https://stackoverflow.com/a/13437997/6792243
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return false;
}
}
|