Appwidget Screen Orientation
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
Solution 1:
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.
privatestaticbooleanisPortrait(Context cx) {
Displayd= ((WindowManager) cx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
if (d.getWidth() == d.getHeight()) {
returnfalse;
} elseif (d.getWidth() < d.getHeight()) {
returntrue;
} else {
returnfalse;
}
}
Hope this helps.
Solution 2:
Define bools.xml in both values-port and values-land
In values-port/bools.xml
<?xml version="1.0" encoding="utf-8"?><resources><boolname="portrait">true</bool></resources>
In values-land/bools.xml
<?xml version="1.0" encoding="utf-8"?><resources><boolname="portrait">false</bool></resources>
Get boolean by Context.getResources() in code
privatestaticbooleanisPortrait(Context context) { return context.getResources().getBoolean(R.bool.portrait); }
Post a Comment for "Appwidget Screen Orientation"