2011-02-03 59 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,所以它只能缩放到可用空间。