I've created a bitmap based app widget for Android homescreens. The whole widget is rendered as one image, and rendered unscaled using an ImageView. To create the bitmap I need to know the exact dimensions of the widget. At the moment I'm doing this by using the Android guidelines for the guaranteed minimum widget dimensions.
Due to what seems like a bug in the Android framework, setting the ImageView scaleType to "center" (which is not supposed to scale the image) does not work when loading the image using a ContentProvider and setImageViewUri(). Instead, the image is scaled depending on the screen dpi. Setting the bitmap (with the property density=DENSITY_NONE) directly to the ImageView using setImageViewBitmap() on the RemoteViews works correctly with scaleType=center, but this method only works for small bitmaps, as the IPC mechanism used has a low limit, and will fail if trying to pass a full 4x4 app widget bimap for example. My current solution is to use images served using ContentProviders, with scaleType=fitXY, and set the layout_width and layout_height of the ImageView in the layout to a fixed number of DPI, then rendering the image to the same size, scaling for screen density. In portrait mode on most phones, this approach works fine. However, in WVGA or generally for landscape tablets, this method does not use the full amount of widget space which is available, and will not fill the width, and/or height of the app widget area. Current dimensioning formula: int widgetWidth = (int)Math.round(((isLandscape ? (106.0f * mWidgetColumns) : (80.0f * mWidgetColumns)) - 2.0f) * dp); int widgetHeight = (int)Math.round(((isLandscape ? (74.0f * mWidgetRows) : (100.0f * mWidgetRows)) - 2.0f) * dp); Subtracting - 2 from the calculated dpi (e.g. 74 * cy - 2) is to avoid cases where the resulting number of pixels is rounded down. (For example in landscape mode on Nexus One, the height is 110, not 111 (74 * 1.5). My questions are: Is there any way in the Android framework to dynamically determine the available widget dimensions? Will there ever be? Are the issues I've encountered confirmed bugs, or are there better solutions to my problems? Some more info here with further links: http://stackoverflow.com/questions/6085946/custom-rendered-android-app-widget -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en