2013-10-23 106 views
2

我有一個Android小部件。我希望它是4個單元格寬度和2個單元格高度。現在小部件的大小是4乘4(出於某種原因)。而奇怪的是,小部件的內容,即幀(根據this definition)尺寸較小。 因此,大多數主屏幕都是空白的,但我無法重新定位窗口小部件(似乎它需要在我的主屏幕上顯示所有4到4個單元格)。 這裏是我的小部件提供商佈局文件的代碼:Android Widget錯誤的尺寸

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:initialLayout="@layout/widget_demo" 
    android:minHeight="110dp" 
    android:minWidth="250dp" 
    android:updatePeriodMillis="1800000" 
    > 
</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="110dp"  
    android:orientation="vertical" 
    android:layout_margin="1sp" 
    android:background="@android:drawable/alert_dark_frame" > 

    <TextView 
     android:id="@+id/widgetTextView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="some_text" 
     android:textColor="#FFFFFF" 
     android:textSize="30dp" /> 



    <Button 
     android:id="@+id/widget_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="some_text" 
     android:textSize="20dp"/> 

</LinearLayout> 

問題是什麼?爲什麼需要4乘4而不是4乘2?

+0

你嘗試將'LinearLayout'從'android:layout_height =「110dp」'更改爲'android:layout_height =「match_父母「? – Dyna

回答

1

應用程序窗口小部件的佈局應是靈活的調整,以適應他們的父容器

因此,改變你的LinearLayout

android:layout_width="wrap_content" 
android:layout_height="110dp" 

匹配父大小

android:layout_width="match_parent" 
android:layout_height="match_parent"