2013-09-23 83 views
0

我有一個用於xhdpi設備(API 14+)的150 x 210 dp窗口部件。當我添加小部件時,它佔用的空間比它應該多。它允許我調整它的大小以佔用較小的空間(但是爲什麼它不是以最小尺寸添加的(就像我調整它的大小時那樣)?)因爲我可以調整它的大小以使它更小,我猜我指定的最小值大小正確的......我的預期是,默認情況下佔據我指定的最小尺寸,不僅當我調整它...Widget佔用額外的單元格

<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文件夾:

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

回答

1

的minWidth和了minHeight正如他們的名字所暗示的,最低限度。他們說圖像可能比這些值大,但不會小。例如,如果將minWidth和minHeight都設置爲100,但您提供的內部大小爲50 x 50的資源a,它將被拉伸至100 x 100.但是,如果您提供的資源大於100 x它將被繪製在它的內在寬度和高度上。

爲了更好的理解,研究android如何在屏幕上繪製視圖。尤其要看在onMeasure中使用MeasureSpecs。對此的一個很好的解釋可以參見FlowLayout example at the end of this video lecture by Romain Guy.

相關問題