From 37e9b7b0ac4ad7bf8edf22540a2427b29376568d Mon Sep 17 00:00:00 2001 From: hupei Date: Mon, 19 Jul 2021 19:12:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DmaxHeight=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 3 +- .../circledialog/sample/MainActivity.java | 3 ++ .../circledialog/AbsBaseCircleDialog.java | 37 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5a7e36d..a13c3b3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,8 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + android:usesCleartextTraffic="true"> params.isShowBottomDivider = true) .setWidth(0.5f) @@ -723,6 +724,8 @@ protected void convert(BaseViewHolder helper, WeiBoItem item) { new CircleDialog.Builder() // .setTypeface(typeface) .setWidth(0.5f) + .setCloseResId(R.mipmap.ic_close, 27) + .setCloseGravity(CloseParams.CLOSE_TOP_RIGHT) .setAdResId(R.mipmap.ic_zfbxcc, (view18, position18) -> { Toast.makeText(MainActivity.this, "点击了" , Toast.LENGTH_SHORT).show(); diff --git a/circledialog/src/main/java/com/mylhyl/circledialog/AbsBaseCircleDialog.java b/circledialog/src/main/java/com/mylhyl/circledialog/AbsBaseCircleDialog.java index 0ccb5a7..f2844c7 100644 --- a/circledialog/src/main/java/com/mylhyl/circledialog/AbsBaseCircleDialog.java +++ b/circledialog/src/main/java/com/mylhyl/circledialog/AbsBaseCircleDialog.java @@ -9,8 +9,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.FrameLayout; import androidx.annotation.ColorInt; import androidx.annotation.FloatRange; @@ -98,21 +100,21 @@ public void onDismiss(DialogInterface dialog) { @Override public void onStart() { -// if (getView() != null && mMaxHeight > 0) { -// getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { -// @Override -// public void onGlobalLayout() { -// int height = getView().getHeight(); -// int screenHeight = mSystemBarConfig.getScreenHeight(); -// int maxHeight = (int) (screenHeight * mMaxHeight); -// if (height > maxHeight) { -// getView().getViewTreeObserver().removeOnGlobalLayoutListener(this); -// getView().setLayoutParams(new FrameLayout.LayoutParams( -// FrameLayout.LayoutParams.MATCH_PARENT, maxHeight)); -// } -// } -// }); -// } + if (getView() != null && mMaxHeight > 0) { + getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + int height = getView().getHeight(); + int screenHeight = mSystemBarConfig.getScreenHeight(); + int maxHeight = (int) (screenHeight * mMaxHeight); + if (height > maxHeight) { + getView().getViewTreeObserver().removeOnGlobalLayoutListener(this); + getView().setLayoutParams(new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, maxHeight)); + } + } + }); + } Dialog dialog = getDialog(); if (dialog != null) { dialog.setCanceledOnTouchOutside(mCanceledOnTouchOutside); @@ -324,11 +326,6 @@ private void setDialogGravity(Dialog dialog) { } else { wlp.width = (int) mWidth; } - if (mMaxHeight > 0 && mMaxHeight <= 1) { - int screenHeight = mSystemBarConfig.getScreenHeight(); - int maxHeight = (int) (screenHeight * mMaxHeight); - wlp.height = maxHeight; - } wlp.gravity = mGravity; wlp.x = mX; wlp.y = mY;