Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分手机左右有边距 #46

Open
Quenstin opened this issue May 29, 2020 · 1 comment
Open

部分手机左右有边距 #46

Quenstin opened this issue May 29, 2020 · 1 comment

Comments

@Quenstin
Copy link

部分手机左右有边距

@smm113522
Copy link

smm113522 commented Nov 15, 2021

改造一下就可以了。

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:id="@+id/item"
    android:layout_height="match_parent">

</LinearLayout>

basedialog 修改为了下面的。。。

package cn.addapp.pickers.common;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.KeyboardShortcutGroup;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import java.util.List;

import cn.addapp.pickers.util.ScreenUtils;
import cn.addapp.pickers.wheelpicker.R;


public abstract class BasicDialog<V extends View> extends Dialog implements DialogInterface.OnKeyListener,
        DialogInterface.OnDismissListener {

    public static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT;
    public static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
    protected Activity activity;
    protected int screenWidthPixels;
    protected int screenHeightPixels;
    //    private Dialog dialog;
    private View view;
    private LinearLayout contentLayout;
    private boolean isPrepared = false;

    public BasicDialog(Activity activity) {
        super(activity, R.style.DialogTheme);
        this.activity = activity;
        DisplayMetrics metrics = ScreenUtils.displayMetrics(activity);
        screenWidthPixels = metrics.widthPixels;
        screenHeightPixels = metrics.heightPixels;
        initDialog();
    }

    private void initDialog() {
        view = View.inflate(activity, R.layout.dialog_custom_layout, null);
        contentLayout = view.findViewById(R.id.item);
        setContentView(contentLayout);

        setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
        setCancelable(true);//按返回键取消窗体
        setOnKeyListener(this);
        setOnDismissListener(this);

        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

//        setSize(screenWidthPixels, WRAP_CONTENT);
    }

    /**
     * 创建弹窗的内容视图
     *
     * @return the view
     */
    protected abstract V makeContentView();

    /**
     * 设置弹窗的内容视图之前执行
     */
    protected void setContentViewBefore() {
    }

    /**
     * 设置弹窗的内容视图之后执行
     *
     * @param contentView 弹窗的内容视图
     */
    protected void setContentViewAfter(V contentView) {
    }

//    public void setContentView(View view) {
//        contentLayout.removeAllViews();
//        contentLayout.addView(view);
//    }

    public void setFitsSystemWindows(boolean flag) {
        contentLayout.setFitsSystemWindows(flag);
    }

//    public void setCanceledOnTouchOutside(boolean flag) {
//        setCanceledOnTouchOutside(flag);
//        setCancelable(false);
//    }

//    public void setCancelable(boolean flag) {
//        setCancelable(flag);
//    }

//    public void setOnDismissListener(final DialogInterface.OnDismissListener onDismissListener) {
////        setOnDismissListener(new DialogInterface.OnDismissListener() {
////            @Override
////            public void onDismiss(DialogInterface dialog) {
////                onDismiss(dialog);
////                onDismissListener.onDismiss(dialog);
////            }
////        });
////        LogUtils.verbose(this, "popup setOnDismissListener");
//    }
//
//    public void setOnKeyListener(final DialogInterface.OnKeyListener onKeyListener) {
////        setOnKeyListener(new DialogInterface.OnKeyListener() {
////            @Override
////            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
////                onKey(dialog, keyCode, event);
////                return onKeyListener.onKey(dialog, keyCode, event);
////            }
////        });
////        LogUtils.verbose(this, "popup setOnKeyListener");
//    }

    /**
     * 设置是否需要重新初始化视图,可用于数据刷新
     */
    public void setPrepared(boolean prepared) {
        isPrepared = prepared;
    }

//    public boolean isShowing() {
//        return isShowing();
//    }

    public final void shows() {
        if (isPrepared) {
            show();
            showAfter();
            return;
        }
//        LogUtils.verbose(this, "do something before popup show");
        setContentViewBefore();
        V view = makeContentView();
        setContentView(view);// 设置弹出窗体的布局
        setContentViewAfter(view);
        isPrepared = true;
        show();
        showAfter();
    }

    protected void showAfter() {
//        LogUtils.verbose(this, "popup show");
    }

//    public void dismiss() {
//        dismissImmediately();
//    }

    protected final void dismissImmediately() {
        if (isShowing())
            dismiss();
    }

//    public boolean onBackPress() {
//        dismiss();
//        return false;
//    }
//
    @Override
    public final boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
//            onBackPress();
            dismiss();
        }
        return false;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        dismiss();
    }

//    public Context getContext() {
//        return activity;
//    }

//    public Window getWindow() {
//        return this;
//    }

    /**
     * 弹框的内容视图
     */
    public View getContentView() {
        // IllegalStateException: The specified child already has a parent.
        // You must call removeView() on the child's parent first.
        return contentLayout.getChildAt(0);
    }

    /**
     * 弹框的根视图
     */
    public ViewGroup getRootView() {
        return contentLayout;
    }

    @Override
    public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, @Nullable Menu menu, int deviceId) {

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}

所有基类就换成这个。。。

show的时候。。。。用shows.........

例如:

fun showdialog(Context context){
val picker = LayoutDatePicker(context)
        picker.setCanLoop(true)
        picker.setWheelModeEnable(true)
        picker.setTopPadding(15)
 
        val config = LineConfig()
        config.color = ContextCompat.getColor(context, R.color.line)//线颜色
        config.alpha = 140//线透明度
        picker.setLineConfig(config)
就是这里的内容了。。。
        picker.shows()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants