2011-02-03 63 views
0

我試圖做一個小部件,這將是4X1。 我設置的提供者遵循線性佈局太大了Widget大小

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
android:minWidth="294dp" 
android:minHeight="72dp" 
android:updatePeriodMillis="0" 
android:initialLayout="@layout/widgetlayout"></appwidget-provider> 

和部件佈局如下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="320dp" 
android:layout_height="100dp" 
android:background="@drawable/widgetframe"> 
<Button android:id="@+id/butscan" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Click Me" /> 
<Button android:id="@+id/butenable" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="On/Off" 
     android:paddingRight="5dip"/> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingLeft="4dip" 
    android:includeFontPadding="false" 
    android:id="@+id/lblcurrent" 
    android:text="Test"/></LinearLayout> 

現在,當我嘗試這在模擬器上,我得到的只是在主屏幕上顯示的該層的中間。背景圖像是來自SDK的4x1肖像圖像(320x100)。

我在想什麼?

回答

0

您的佈局寬度和高度爲的LinearLayout可能應該FILL_PARENT。

你的按鈕沒有任何圖形資源,但我認爲你在代碼中指定了類似drawables或bitmaps的東西,否則它們可能不會顯示。我從來沒有創建過一個沒有圖像的按鈕,所以我不知道它會如何行動。

我很驚訝,你的'測試'文本沒有顯示,但它可能在你的小部件的大小之外,因爲你的背景比部件本身更大。再次嘗試fill_parent,而不是320dp和100dp(順便說一句,我從來沒有用過'dp'only'sp')。

0

由於fill_parent,您的TextView正在接管佈局。

您應該添加layout_weight=1,所以它只能縮放到可用空間。