【问题标题】:DatePickerDialog leaves white space androidDatePickerDialog 留下空白 android
【发布时间】:2020-03-16 06:46:22
【问题描述】:

我有一个日期选择器对话框,

当对话框打开时,它会显示如图所示的空白区域(在 datePicker 的右侧),

我尝试设置布局参数

DatePickerDialog dialog = new DatePickerDialog(_context, this,
                _birthYear, _month,
                _day);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.getDatePicker().setLayoutParams(params);
        dialog.setCancelable(false);
        dialog.getDatePicker().setSpinnersShown(false);
        dialog.getDatePicker().setCalendarViewShown(true);

还是不行

有什么建议吗??

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    最好的方法是在代码中使用比例。

    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical">
                <DatePicker
                    android:id="@+id/datePicker"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="37dp"
                    android:scaleX="1.2"
                    android:scaleY="1.2"/>
    </LinearLayout>
    

    试试这个代码,希望对你有帮助

    【讨论】:

    • 空白已删除,但它损坏了视图,无法使用,但感谢您的建议。
    • What issue you get share that issue
    • 我一直在从其样式将最小和最大高度和宽度设置为 90% 的活动中调用 DatePickerDialog,我尝试对日期选择器对话框使用不同的样式: DatePickerDialog dialog = new DatePickerDialog(_context, R.style. AppTheme_popDate ,this, _birthYear, _month, _day);还是不行
    【解决方案2】:

    在这里尝试将宽度设置为 MATCH_PARENT。

    ViewGroup.LayoutParams.WRAP_CONTENT, 
    

    到:

    ViewGroup.LayoutParams.MATCH_PARENT, 
    

    更新答案:

    日期选择器对话框和您的 查看。

    尝试像这样设置对话框的大小:

    datepikerdialog.getWindow().setLayout(width,height)
    

    【讨论】:

    • 尝试将DAtepicker的宽高设置为wrapcontent。你的尺码好像有问题。请检查更新的答案。
    • 好的,我刚刚发现了问题,我一直在从其样式将最小和最大高度和宽度设置为 90% 的活动中调用 DatePickerDialog,我尝试对日期选择器对话框使用不同的样式:DatePickerDialog dialog = new DatePickerDialog (_context, R.style.AppTheme_popDate ,this, _birthYear, _month, _day);还是不行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 2023-04-06
    • 2023-03-03
    • 1970-01-01
    • 2012-05-28
    • 2021-10-02
    相关资源
    最近更新 更多