2012-02-10 23 views
1

我appwidget與以下部件提供商,信息小部件花費的時間比它應該

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:configure="de.firepower.andwol.widget.AndWOLWidgetConfigure" 
    android:initialLayout="@layout/widget" 
    android:minHeight="72dp" 
    android:minWidth="72dp" 
    android:previewImage="@drawable/icon" 
    android:resizeMode="horizontal|vertical" 
    android:updatePeriodMillis="180000" > 

</appwidget-provider> 

和佈局如下定義更多的地方...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="@dimen/widget_margin" android:orientation="vertical" android:background="@drawable/appwidget_dark_bg"> 
    <ImageButton 
     android:id="@+id/widgetbutton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:src="@drawable/icon" 
     android:scaleType="fitCenter" 
     android:contentDescription="@string/cd_wake_host"> 
    </ImageButton> 
    <TextView 
     android:id="@+id/widgettext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="@string/placeholder_hostname" android:textSize="8dp" 
     android:layout_marginBottom="2dp"/> 
</LinearLayout> 

我認爲應該採取的1x1平方但它需要2x2格,我不知道爲什麼。如果我在Widget-Provider-Info中定義minHeight和Width小於60dp,我只能得到1x1。 有誰知道/看我做錯了什麼?

在此先感謝:-)

回答

2

看看這裏: http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#anatomy_determining_size

爲了得到你需要設置你的尺寸舍40dp在高度和寬度1x1的單元格大小的小部件。

+0

呵呵,從沒想過會那麼容易。謝謝! :-) – Thomas 2012-02-10 07:08:34

+0

只是爲了澄清;顯然72是針對ICS之前的,但是由於40輪最多可以有1個單元,所以所有設備都可以使用40個單元。當你有多個單元跨度時,你會遇到一些麻煩。 – MrJre 2012-04-04 13:07:11

相關問題