|
@@ -27,7 +27,7 @@ import static android.view.View.MeasureSpec.EXACTLY;
|
|
|
* @createTime: 2019/9/24 17:34
|
|
|
*/
|
|
|
public class MaxRelativeLayout extends RelativeLayout {
|
|
|
-
|
|
|
+
|
|
|
private int maxWidth;
|
|
|
private int maxHeight;
|
|
|
private int minWidth;
|
|
@@ -35,24 +35,24 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
private boolean lockWidth;
|
|
|
private boolean interceptTouch = true;
|
|
|
private View contentView;
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout(Context context) {
|
|
|
super(context);
|
|
|
init(context, null);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout(Context context, AttributeSet attrs) {
|
|
|
super(context, attrs);
|
|
|
init(context, attrs);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
init(context, attrs);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private float startAnimValue = 0, endAnimValue = 0;
|
|
|
-
|
|
|
+
|
|
|
private void init(Context context, AttributeSet attrs) {
|
|
|
if (attrs != null) {
|
|
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogXMaxLayout);
|
|
@@ -62,12 +62,12 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
minHeight = a.getDimensionPixelSize(R.styleable.DialogXMaxLayout_minLayoutHeight, 0);
|
|
|
lockWidth = a.getBoolean(R.styleable.DialogXMaxLayout_lockWidth, false);
|
|
|
interceptTouch = a.getBoolean(R.styleable.DialogXMaxLayout_interceptTouch, true);
|
|
|
-
|
|
|
+
|
|
|
a.recycle();
|
|
|
}
|
|
|
minWidth = minWidth == 0 ? getMinimumWidth() : minWidth;
|
|
|
minHeight = minHeight == 0 ? getMinimumHeight() : minHeight;
|
|
|
-
|
|
|
+
|
|
|
if (!isInEditMode()) {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
animate().setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
@@ -81,14 +81,14 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private ScrollView childScrollView;
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout setMaxHeight(int maxHeight) {
|
|
|
if (maxHeight > 0) this.maxHeight = maxHeight;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout setMaxWidth(int maxWidth) {
|
|
|
if (maxWidth > 0) this.maxWidth = maxWidth;
|
|
|
return this;
|
|
@@ -104,15 +104,15 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
}
|
|
|
|
|
|
private int preWidth = -1;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
|
|
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
|
|
-
|
|
|
+
|
|
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
-
|
|
|
+
|
|
|
if (preWidth == -1 && widthSize != 0) {
|
|
|
preWidth = widthSize;
|
|
|
}
|
|
@@ -120,10 +120,10 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
maxWidth = Math.min(maxWidth, Math.min(widthSize, preWidth));
|
|
|
}
|
|
|
if (heightSize > maxHeight && maxHeight != 0) {
|
|
|
- heightSize = maxHeight;
|
|
|
+ heightSize = maxHeight + getPaddingBottom() + getPaddingTop();
|
|
|
}
|
|
|
if (widthSize > maxWidth && maxWidth != 0) {
|
|
|
- widthSize = maxWidth;
|
|
|
+ widthSize = maxWidth + getPaddingLeft() + getPaddingRight();
|
|
|
}
|
|
|
View blurView = findViewWithTag("blurView");
|
|
|
View contentView = this.contentView == null ? findViewWithoutTag("blurView") : this.contentView;
|
|
@@ -132,7 +132,7 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
int heightTemp = contentView.getMeasuredHeight() == 0 ? getMeasuredHeight() : contentView.getMeasuredHeight();
|
|
|
if (widthTemp < minWidth) widthTemp = minWidth;
|
|
|
if (heightTemp < minHeight) heightTemp = minHeight;
|
|
|
-
|
|
|
+
|
|
|
LayoutParams lp = (LayoutParams) blurView.getLayoutParams();
|
|
|
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
|
lp.width = widthTemp;
|
|
@@ -146,14 +146,14 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
blurView.setLayoutParams(lp);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
int maxHeightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
|
|
|
int maxWidthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
|
|
|
super.onMeasure(maxWidthMeasureSpec, maxHeightMeasureSpec);
|
|
|
-
|
|
|
+
|
|
|
childScrollView = findViewById(R.id.scrollView);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private View findViewWithoutTag(String tag) {
|
|
|
for (int i = 0; i < getChildCount(); i++) {
|
|
|
if (!tag.equals(getChildAt(i).getTag())) {
|
|
@@ -162,7 +162,7 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Deprecated
|
|
|
public boolean isChildScrollViewCanScroll() {
|
|
|
if (childScrollView == null) return false;
|
|
@@ -176,31 +176,31 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public int dip2px(float dpValue) {
|
|
|
final float scale = getResources().getDisplayMetrics().density;
|
|
|
return (int) (dpValue * scale + 0.5f);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public boolean isLockWidth() {
|
|
|
return lockWidth;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout setLockWidth(boolean lockWidth) {
|
|
|
this.lockWidth = lockWidth;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private OnYChanged onYChangedListener;
|
|
|
-
|
|
|
+
|
|
|
int navBarHeight;
|
|
|
Paint navBarPaint;
|
|
|
-
|
|
|
+
|
|
|
public void setNavBarHeight(int height) {
|
|
|
navBarHeight = height;
|
|
|
invalidate();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
super.onDraw(canvas);
|
|
@@ -212,44 +212,44 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
canvas.drawRect(0, getHeight() - navBarHeight, getWidth(), getHeight(), navBarPaint);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void setContentView(View contentView) {
|
|
|
this.contentView = contentView;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public interface OnYChanged {
|
|
|
void y(float y);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setY(float y) {
|
|
|
super.setY(y);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public OnYChanged getOnYChanged() {
|
|
|
return onYChangedListener;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public MaxRelativeLayout setOnYChanged(OnYChanged onYChanged) {
|
|
|
this.onYChangedListener = onYChanged;
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setTranslationY(float translationY) {
|
|
|
super.setTranslationY(translationY);
|
|
|
if (onYChangedListener != null) onYChangedListener.y(translationY);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private OnTouchListener onTouchListener;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setOnTouchListener(OnTouchListener l) {
|
|
|
onTouchListener = l;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
boolean reInterceptTouch;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
if (onTouchListener != null) {
|
|
@@ -257,7 +257,7 @@ public class MaxRelativeLayout extends RelativeLayout {
|
|
|
}
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
return reInterceptTouch;
|