如何在DatePickerDialog中删除空格?

时间:2017-12-12 19:08:12

标签: android

当我在大屏幕上启动应用程序时,我在DatePickerDialog的右侧有一个额外的空间。

对话框的源代码:

val datePicker = DatePickerDialog.OnDateSetListener { 
view, year, monthOfYear, dayOfMonth -> if (view.isShown) { 
myCalendar.set(Calendar.YEAR, year)
 myCalendar.set(Calendar.MONTH, monthOfYear) 
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
 addTimer(isAct) 
}
 } 
DatePickerDialog(this, datePicker, myCalendar!! .get(Calendar.YEAR), myCalendar!!.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show()

有人可以告诉你如何调整它吗?谢谢 screen

3 个答案:

答案 0 :(得分:0)

您可以将布局参数设置为换行内容,以删除日期选择器对话框的空白区域。对话框将位于窗口的中心。 试试这个 -

@Override
public void onStart() { 
    // This MUST be called first! Otherwise, the view tweaking will not be present in the displayed Dialog (most likely overridden)
    super.onStart();

    makeWrapContent(myCustomView);
}

制作视图包装内容的简单方法 -

protected void makeWrapContent(View v) {

    View current = v;          
    do {
        // Get the parent
        ViewParent parent = current.getParent();    

        // Check if the parent exists
        if (parent != null) {
            // Get the view
            try {
                current = (View) parent;
            } catch (ClassCastException e) {
                break;
            }

            // Modify the layout
            current.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
        }
    } while (current.getParent() != null);

    // Request a layout to be re-done
    current.requestLayout();
}

答案 1 :(得分:0)

将您的XML文件更改为

匹配父级以包装内容

def n_dimensional_euclidean_distance(a, b): """ Returns the euclidean distance for n>=2 dimensions :param a: tuple with integers :param b: tuple with integers :return: the euclidean distance as an integer """ dimension = len(a) # notice, this will definitely throw a IndexError if len(a) != len(b) return sqrt(reduce(lambda i,j: i + ((a[j] - b[j]) ** 2), range(dimension), 0))

答案 2 :(得分:0)

我也遇到过类似的问题。就我而言,我是在传递对话框上下文而不是活动上下文。

您在哪里显示DatePickerDialog? (来自对话框,活动或片段)检查将什么上下文传递给DatePickerDialog。

要快速修复,请尝试传递DatePickerDialog的活动(活动,...) 以便始终获取活动上下文。

Java DatePickerDialog(getActivity(),...)

科特琳 DatePickerDialog(活动,...)