user1460819
user1460819

Reputation: 2112

Android Widget Wrong Size

I have an Android widget. I would like it to be 4 cells width and 2 cells height. Right now the size of the widget is 4 by 4 (for some reason). And the strange thing is that the content of the widget, i.e. the frame (according to this definition) is of small size. So, most of the home screen is blank, but I cannot reposition the widget (seems that it takes all 4 by 4 cells on my home screen). Here is the code of my widget-provider layout file:

<?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>

Here is the widget layout:

<?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>

What is the problem? Why does it take 4 by 4 instead of 4 by 2?

Upvotes: 2

Views: 862

Answers (1)

Dyna
Dyna

Reputation: 2305

App Widget layouts should be flexible, resizing to fit their parent container

So, change your LinearLayout

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

to match parent size

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

Upvotes: 1

Related Questions