计算appwidget高度 [英] Calculate height of appwidget

查看:501
本文介绍了计算appwidget高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找出或发现通过谷歌搜索这个问题的解决方案。我有一个appwidget一个Android应用程序,看起来像 http://www.livescorewidget.eu/ IMG / screendumps / widget.png 和我在飞行中添加的数据行。由于不同的设备的部件的高度是不同的,因此不同量的空间是供我的行。我想知道有多少骤降或像素我的小部件使用,所以我可以计算出有多少行有空间。这可能吗?

I cannot figure out or find a solution by googling for this problem. I have an android app with an appwidget, looks like http://www.livescorewidget.eu/img/screendumps/widget.png, and I am adding the data rows on the fly. Due to different devices the height of the widget is different and therefore a different amount of space is available for my rows. I want to know how many dips or pixels my widget uses so I can calculate how many rows there is room for. Is it possible?

更好的可能是,如果你可以计算出有多少高度可用的行布局。

Even better could be if you could calculate how much height available in the layout for the rows.

感谢

推荐答案

从果冻豆起,你可以得到一个捆绑对象包含使用 getAppWidgetOptions()的方法 AppWidgetManager

From Jelly Bean onwards you can get a Bundle object containing widget dimensions using the getAppWidgetOptions() method in AppWidgetManager:

Bundle options = appWidgetManager.getAppWidgetOptions(widgetId);

int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
int maxWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH);

int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
int maxHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);

了minWidth 了maxHeight 是窗口小部件的尺寸时,该设备是纵向,了maxWidth 了minHeight 的尺寸时,该设备为横向。所有的DP。

minWidth and maxHeight are the dimensions of your widget when the device is in portrait orientation, maxWidth and minHeight are the dimensions when the device is in landscape orientation. All in dp.

这篇关于计算appwidget高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆