具有方形布局的应用程序小部件在横向模式下无法正确显示

发布于 2024-12-07 08:35:43 字数 960 浏览 0 评论 0原文

我已经构建了一个具有方形布局的应用程序小部件,因此它不完全适合 http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#sizes

我选择了 3x2 尺寸 (android:minWidth="220dip" android:minHeight="146dip"),因为它是覆盖小部件布局的最小尺寸。

http://developer.android.com/guide/practices/ui_guidelines/ widget_design.html#design Google 建议:

“所有小部件都必须适合六种受支持的小部件尺寸之一的边界框,或者更好的是,在一对纵向和横向方向尺寸内,这样您的小部件当用户切换屏幕方向时看起来不错”

我的小部件在纵向模式下看起来不错。当切换到横向模式(在模拟器中)时,布局将被裁剪。我尝试反转提供程序 XML 中的 minWidth 和 minHeight 值,然后它在横向模式下看起来很完美,但在纵向模式下被剪裁。将大小设置为 3x3 可以解决问题,但是小部件会占用大量不必要的空间。

我知道我可以在 res/layout 和 res/layout-land 中定义不同的布局,但在这种情况下,布局根本没有不同,在两种模式下我希望小部件看起来是方形的。 我需要的是像“xml”和“xml-land”之类的东西,据我所知,Android 不支持这个。

有想法吗?

I have built an appwidget with an square layout, and so it doesn't fit exactly in the standard widget sizes as recommended in http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#sizes.

I chose a 3x2 size (android:minWidth="220dip" android:minHeight="146dip") as it is the smalllest that covers the widget's layout.

In http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#design Google recommends:

"All widgets must fit within the bounding box of one of the six supported widget sizes, or better yet, within a pair of portrait and landscape orientation sizes, so your widget looks good when the user switches screen orientations"

My widget looks good in portrait mode. When switched to landscape mode (in the emulator) the layout is clipped. I tried inverting the minWidth and minHeight values in the provider's XML and then it looked perfect in landscape mode but clipped in portrait mode. Setting the size to 3x3 solves the problem, but then the widgets takes a lot of unnecessary space.

I know I can define different layouts in res/layout and res/layout-land, but in this case the layouts are not different at all, in both modes I want the widget to look square.
What I would need is something like 'xml' and 'xml-land', AFAIK this is not supported in Android.

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-12-14 08:35:43

我需要的是“xml”和“xml-land”之类的东西,据我所知,Android 不支持这个。

是支持的。所有资源类型都支持所有资源集限定符(例如,-land)。

它是否对您有帮助完全是另一回事,因为我不知道您可以通过这种方式动态更改实际的应用程序小部件大小。

将大小设置为 3x3 可以解决问题,但是小部件会占用大量不必要的空间。

您是那个试图强制使用特定像素大小(或至少是宽高比)的人。正如您所发现的,这将是脆弱的。此外,不保证应用程序小部件单元格在所有设备和主屏幕实现上具有相同的大小。

因此,您要么需要选择一个应用程序小部件大小,为您提供大量额外空间(您的 3x3 场景),要么设计一个流畅的应用程序小部件布局,以适应给定的实际大小(因此不会正方形)。就我个人而言,我推荐后者。

What I would need is something like 'xml' and 'xml-land', AFAIK this is not supported in Android.

It is supported. All resource set qualifiers (e.g., -land) are supported for all resource types.

Whether it will help you is another matter entirely, as I am not aware that you can change actual app widget size on the fly this way.

Setting the size to 3x3 solves the problem, but then the widgets takes a lot of unnecessary space.

You are the one who is trying to force a particular pixel size (or, at least, aspect ratio). This will be fragile, as you are discovering. Furthermore, app widget cells are not guaranteed to be the same size on all devices and home screen implementations.

Hence, you are either going to need to choose an app widget size that gives you tons of extra space (your 3x3 scenario), or design a fluid app widget layout that adapts to the actual size that you are given (and therefore will not be square). Personally, I recommend the latter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文