李堇 2022-09-06 11:10 采纳率: 52.8%
浏览 41
已结题

android 页面弹出对话框导致页面列表第一行高度异常变化

在页面中弹出一个对话框,导致页面中fragment列表的第一行的高度突然异常变化,请问有哪位遇见过类似问题?
如图;

img

对话框创建代码:
CustomDialog customDialog = new CustomDialog(hop.getContext());
                    customDialog.setTitle("退出当前账号?").setCancle("取消", new CustomDialog.IOnCancelListener() {
                        @Override
                        public void onCancel(CustomDialog dialog) {
                            //ToastUtil.showShort(homePageActivity.this, "取消不生成!");
                        }
                    }).setConfirm("确定", new CustomDialog.IOnConfirmListener() {
                        @Override
                        public void onConfirm(CustomDialog dialog) {
                            Intent intent = new Intent(homePageActivity.this, FullscreenActivity.class);
                            startActivity(intent);
                        }
                    }).show();

//对话框类
public class CustomDialog extends Dialog implements View.OnClickListener {

    private TextView mTvTitle,mTvMessage,mTvCancel,mTvConfirm;
    private String title,message,cancle,confirm;

    private IOnCancelListener cancelListener;
    private IOnConfirmListener confirmListener;

    public String getTitle() {
        return title;
    }

    public CustomDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public CustomDialog setMessage(String message) {
        this.message = message;
        return this;
    }

    public String getCancle() {
        return cancle;
    }

    public CustomDialog setCancle(String cancle,IOnCancelListener listener) {
        this.cancle = cancle;
        this.cancelListener = listener;
        return this;
    }

    public String getConfirm() {
        return confirm;
    }

    public CustomDialog setConfirm(String confirm,IOnConfirmListener listener) {
        this.confirm = confirm;
        this.confirmListener = listener;
        return this;
    }

    public CustomDialog(@NonNull Context context) {
        super(context);

    }

    public CustomDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        setContentView(R.layout.custom_dialog);
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = getWindow().getAttributes();
        Point size = new Point();
        d.getSize(size);
        p.width = (int)(size.x * 0.25);
        getWindow().setAttributes(p);

        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvMessage = (TextView) findViewById(R.id.tv_message);
        mTvCancel = (TextView) findViewById(R.id.tv_cancle);
        mTvConfirm = (TextView) findViewById(R.id.tv_confirm);
        if(!TextUtils.isEmpty(title)) {
            mTvTitle.setText(title);
        }
        if(!TextUtils.isEmpty(message)) {
            mTvMessage.setText(message);
        }
        if(!TextUtils.isEmpty(cancle)) {
            mTvCancel.setText(cancle);
        }
        if(!TextUtils.isEmpty(confirm)) {
            mTvConfirm.setText(confirm);
        }
        mTvCancel.setOnClickListener(this);
        mTvConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_cancle:
                if(cancelListener != null) {
                    cancelListener.onCancel(this);
                }
                dismiss();
                break;
            case R.id.tv_confirm:
                if(confirmListener != null) {
                    confirmListener.onConfirm(this);
                }
                dismiss();
                break;
        }
    }

    public interface IOnCancelListener{
        void onCancel(CustomDialog dialog);
    }

    public interface IOnConfirmListener{
        void onConfirm(CustomDialog dialog);
    }
}

对话框布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/mianV"
        android:layout_width="@dimen/dp_720"
        android:layout_height="@dimen/dp_200"
        android:orientation="vertical"
        android:gravity="center">
        <TextView
            android:id="@+id/first"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_10"
            android:textColor="@color/black"
            android:text=""/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_40"
            android:textColor="@color/black"
            android:gravity="center"
            android:background="@drawable/sharp7"
            android:text=""/>
        <TextView
            android:id="@+id/tv_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/dp_12"
            android:textColor="@color/black"
            android:textStyle="bold"
            android:gravity="center"
            android:paddingTop="@dimen/dp_2"
            android:background="#ffffff"
            android:text=""/>

        <TextView
            android:id="@+id/tv_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:gravity="center"
            android:paddingLeft="@dimen/dp_10"
            android:paddingRight="@dimen/dp_10"
            android:paddingTop="@dimen/dp_2"
            android:paddingBottom="@dimen/dp_2"
            android:text=""
            android:textColor="@color/black"
            android:textSize="@dimen/dp_8"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_40"
            android:orientation="horizontal"
            android:background="@drawable/sharp8">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/tv_cancle"
                    android:layout_width="@dimen/dp_35"
                    android:layout_height="@dimen/dp_20"
                    android:textSize="@dimen/dp_8"
                    android:textColor="#ffffff"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:background="@drawable/sharp9"
                    android:text="取消"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/tv_confirm"
                    android:layout_width="@dimen/dp_35"
                    android:layout_height="@dimen/dp_20"
                    android:textSize="@dimen/dp_8"
                    android:textColor="#ffffff"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:background="@drawable/sharp10"
                    android:text="确认"/>
            </LinearLayout>


        </LinearLayout>
    </LinearLayout>
    <ImageView
        android:layout_width="@dimen/dp_60"
        android:layout_height="@dimen/dp_60"
        android:src="@mipmap/exit_bgc"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/dp_18"
        />
</RelativeLayout>

  • 写回答

1条回答 默认 最新

  • 灯塔@kuaidao 2022-09-12 12:56
    关注

    使用布局查看器定位下原因。dialog是一个浮动在上层的window,不会影响界面的布局。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月9日
  • 修改了问题 9月6日
  • 创建了问题 9月6日

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b