Android widget size issue on orientation change

2019-08-28 20:17发布

问题:

Got some problems with my widget. When i put it on destop (eg 3x3 size) i can see following resize frame after long press on widget:

Lets say, its ok. But when i change phone orientation to horizontal i got this:

My widget get smaller and got wide resize frame

As i measured, widget widgh is same as widget height previous orientation.

Ok, so lets make resize frame little smaller to get some additional room on screen:

Now change phone orientation again and:

Widget size is crappy again.

Whut i doing wrong?

This is my Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.widget.twil.jacob"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8"/>

<application
    android:allowBackup="false"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:configChanges="orientation|screenSize">
    <receiver
        android:label="@string/small_name"
        android:name="MyWidgetProvidersmall"
        android:icon="@drawable/icon">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_info_small" />
    </receiver>
    <receiver
        android:label="@string/medium_name"
        android:name="MyWidgetProvidermedium"
        android:icon="@drawable/icon">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_info_medium" />
    </receiver>
    <receiver
        android:label="@string/large_name"
        android:name="MyWidgetProviderlarge"
        android:icon="@drawable/icon">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_info_large" />
    </receiver>
</application>
</manifest>

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:orientation="vertical"
android:id="@id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<ImageView
android:id="@id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:scaleType="centerInside"
android:src="@drawable/sticker" />
</FrameLayout>

and one of info files for different sizes (1x1 2x2 3x3)

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget_layout"
android:minHeight="@dimen/AppWidget_3Cell"
android:minWidth="@dimen/AppWidget_3Cell"
android:resizeMode="horizontal|vertical" />

any sugestions? Thanks. Amalia.