DatePickerDialog 弹出时留下了空白空间,安卓系统。

huangapple 未分类评论55阅读模式
标题翻译

DatePickerDialog leaves white space android

问题

我有一个日期选择对话框,每当对话框打开时,它都会显示如图所示的白色空白区域(在日期选择器的右侧)。

我尝试过设置布局参数:

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);

但仍然不起作用。有什么建议吗?

英文翻译

I have a date picker dialog ,DatePickerDialog 弹出时留下了空白空间,安卓系统。

when ever dialog opens it shows the white space as shown in image(in right side of datePicker) ,

i tried setting layout Params

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);

still it aint working

any suggestions??

答案1

得分: 0

这里最好的适应方法是在您的代码中使用缩放。

<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>

试试这段代码,希望能对您有所帮助。

英文翻译

Here is the best way to fit this is to use scale in your code.

&lt;LinearLayout
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:gravity=&quot;center&quot;
            android:orientation=&quot;vertical&quot;&gt;
            &lt;DatePicker
                android:id=&quot;@+id/datePicker&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_gravity=&quot;center&quot;
                android:layout_marginTop=&quot;37dp&quot;
                android:scaleX=&quot;1.2&quot;
                android:scaleY=&quot;1.2&quot;/&gt;
&lt;/LinearLayout&gt;

Try out this code I hope that will help you

答案2

得分: 0

尝试在此处将宽度设置为MATCH_PARENT。

ViewGroup.LayoutParams.WRAP_CONTENT,

更改为:

ViewGroup.LayoutParams.MATCH_PARENT,

更新后的回答:

日期选择对话框的尺寸似乎与您的视图不匹配。

尝试像这样设置对话框的尺寸:

datepikerdialog.getWindow().setLayout(width,height)
英文翻译

Try to set the width to MATCH_PARENT over here.

ViewGroup.LayoutParams.WRAP_CONTENT, 

TO:

ViewGroup.LayoutParams.MATCH_PARENT, 

Updated ans:

> There seems to be a size mismatch with the datepicker dialog and your
> view.

Try setting the size of the dialog like this:

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

huangapple
  • 本文由 发表于 2020年3月16日 14:46:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/60701433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定