[英]Android DialogPreference width
I have a custom DialogPreference
that just contains a date picker. 我有一个仅包含日期选择器的自定义
DialogPreference
。 Everything works fine EXCEPT the dialog has a huge border and title around it as can be seen below. 除了对话框具有巨大的边框和标题之外,其他所有内容都可以正常运行,如下所示。
I would like the dialog to just be the date picker: 我希望对话框只是日期选择器:
I've figured out how to remove the title by setting the window title to null, but the massive border still exists. 我已经想出了如何通过将窗口标题设置为null来删除标题的方法,但是大边框仍然存在。
My custom layout: 我的自定义布局:
<?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:layout_height="match_parent">
<DatePicker
android:id="@+id/birthdayPicker"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:calendarViewShown="false"/>
</LinearLayout>
I've tried setting the linear layouts width/height to wrap_content
, setting negative margins, and a host of other hackey solutions but nothing seems to be working. 我试过将线性布局的width / height设置为
wrap_content
,设置负边距,以及其他许多hackey解决方案,但似乎没有任何效果。
The only luck I've had so far is overriding onShow
and programmatically setting the windows size to some arbitrary amount - like a width of 300dp. 到目前为止,我唯一的运气是重写
onShow
并以编程方式将窗口大小设置为任意大小-例如300dp的宽度。 This is obviously super duper hackey and I'd prefer a more elegant solution. 这显然是超级骗子hackey,我希望有一个更优雅的解决方案。 Any help would be much appreciated guys!
任何帮助将不胜感激的家伙!
<?xml version="1.0" encoding="utf-8"?>
Your LinearLayout
should not be match_parent
but wrap_content
eg the DatePicker
's dimensions. 您的
LinearLayout
不应为match_parent
而应为wrap_content
例如DatePicker
的尺寸。
Try: 尝试:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<DatePicker
android:id="@+id/birthdayPicker"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:calendarViewShown="false"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.