0

I have a 150 x 210 dp widget for xhdpi devices (API 14+). When I add the widget, it occupies more space than it should. It allows me to resize it to occupy smaller space (but WHY it isn't added at the minimum size(like when I resize it)? ) Because I cand resize it to make it smaller, I guess the values I specified for the minimum size are correct... My expectation would be to occupy by default the minimum size I specified, not only when I resize it...

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="@dimen/recording_widget_min_width"
    android:minHeight="@dimen/recording_widget_min_height"
    android:updatePeriodMillis="86400000"
    android:previewImage="@drawable/ic_launcher"
    android:initialLayout="@layout/recording_widget_layout"
    android:resizeMode="horizontal|vertical"
    android:widgetCategory="home_screen">    
</appwidget-provider>

values-xhdpi-v14 folder:

<resources>
    <dimen name="recording_widget_min_width">150dp</dimen>
    <dimen name="recording_widget_min_height">210dp</dimen>        
</resources>
4

1 回答 1

1

minWidth 和 minHeight 顾名思义就是最小值。他们说图像可以大于这些值,但不能更小。

例如,如果您将 minWidth 和 minHeight 都设置为 100,但您提供的资源 a 的固有大小为 50 x 50,它将被拉伸到 100 x 100。但如果您提供的资源大于 100 x 100,它将是以它的固有宽度和高度绘制。

为了更好地理解,研究 android 如何将视图绘制到屏幕上。特别看一下 onMeasure 中 MeasureSpecs 的使用。可以在Romain Guy 的视频讲座末尾的 FlowLayout 示例中看到对此的一个很好的解释。

于 2013-09-23T23:47:40.113 回答