Skip to content

Commit

Permalink
修复maxHeight失效
Browse files Browse the repository at this point in the history
  • Loading branch information
hupei committed Jul 19, 2021
1 parent f8a51bb commit 37e9b7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<meta-data
android:name="design_width_in_dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
dialogFragment = new CircleDialog.Builder()
//.setTypeface(typeface)
.setTitle("标题")
.setMaxHeight(0.8f)
//.setManualClose(true)
.configTitle(params -> params.isShowBottomDivider = true)
.setWidth(0.5f)
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 37e9b7b

Please sign in to comment.