AppWidget屏幕方向 [英] AppWidget Screen Orientation

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

问题描述

下面是我的问题。我有一个纵向屏幕方向的作品完美的appwidget。然而,当我改变了我的屏幕方向为横向我appWidget的宽度和高度由主屏幕启动自动改变,问题是在横向模式下我的小部件的高度不是由主屏幕发射器设置正确。
所以,我需要检测的屏幕方向改变和重新大小我appwidget。我GOOGLE了它但我仍然没有任何想法我怎么能做到这一点。如果它是一个活动很简单,但事实并非如此。我会是如果任何人有这个想法gratefull。

Here is my question. I have an appwidget which works perfectly in a portrait screen orientation. However, When i changed my screen orientation to landscape my appWidget's width and height changing automatically by the home screen launcher and the problem is in landscape mode my widget's height is not set properly by the homescreen launcher. So, I need to detect is screen orientation changed and re-size my appwidget. I've googled it but still i don't have any idea how can i do that. If it was an activity it was simple but it's not. I'll be gratefull if anyone has idea about this.

推荐答案

在屏幕的方向改变你的AppWidgetProvider的onUpdate方法被调用。您可以使用下面的函数来获得,如果你是在肖像或风景模式,然后更新基于远程的看法。

When the screen orientation changes your AppWidgetProvider onUpdate method gets called. You can use the following function to get if you are in portrait or landscape mode and then update your remote views based on that.

private static boolean isPortrait (Context cx) {
Display d = ((WindowManager) cx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

if (d.getWidth() == d.getHeight()) {
    return false;
} else if (d.getWidth() < d.getHeight()) {
    return true;    
} else {
    return false;
}
}

希望这有助于。

这篇关于AppWidget屏幕方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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