MaxHeightScrollView.java
1.32 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
package com.wd.common.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ScrollView;
import com.wd.fastcoding.base.R;
import com.wd.foundation.wdkit.utils.UiUtils;
/**
* 描述:最大滚动高度
*
* @author : lvjinhui
* @since: 2023/11/2
*/
public class MaxHeightScrollView extends ScrollView {
private int maxHeight;
public MaxHeightScrollView(Context context) {
this(context, null);
}
public MaxHeightScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MaxHeightScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaxHeightScrollView);
maxHeight = typedArray.getDimensionPixelSize(R.styleable.MaxHeightScrollView_maxScrollHeight,
UiUtils.dp2px(R.dimen.rmrb_dp330));
typedArray.recycle();
}
public void setMaxHeight(int maxHeight){
this.maxHeight = maxHeight;
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST));
}
}