当前位置: 动力学知识库 > 问答 > 编程问答 >

xml - Android Widget - Need 4x2 widget Getting 1x1 widget

问题描述:

I'm developing my first widget.

(Testing on Sony Xperia Go)

this is my widget_info.xml

<?xml version="1.0" encoding="utf-8"?>

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" >

<appwidget-provider

xmlns:android="http://schemas.android.com/apk/res/android"

android:initialLayout="@layout/layout_widget"

android:minHeight="110dp"

android:minWidth="250dp"

android:updatePeriodMillis="180000" />

</appwidget-provider>

I'm using this formula to caluclate minHeigh and minWidth

70 × n − 30 As per given Here

Expecting:

Getting:

Here is my widget_layout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="8dip"

android:background="@drawable/background_semi_transparent_black"

android:orientation="vertical" >

<LinearLayout

android:id="@+id/upper_row"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:padding="10dp" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_weight="2"

android:orientation="vertical" >

<TextView

android:id="@+id/word"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Word" />

<TextView

android:id="@+id/meaning"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Meaning.." />

</LinearLayout>

<ImageView

android:id="@+id/shuffle"

android:layout_width="32dp"

android:layout_height="32dp"

android:layout_weight="1"

android:contentDescription="Shuffle Word List"

android:src="@drawable/shuffle" />

</LinearLayout>

<TextView

android:id="@+id/textView1"

android:layout_width="fill_parent"

android:layout_height="1dp"

android:background="#999"

android:text="" />

<LinearLayout

android:id="@+id/lower_row"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:padding="10dp" >

<ImageView

android:id="@+id/imageView2"

android:layout_width="32dp"

android:layout_height="32dp"

android:layout_gravity="left"

android:layout_weight="1"

android:gravity="left"

android:scaleType="fitStart"

android:src="@drawable/previous" />

<TextView

android:id="@+id/list_title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:layout_weight="2"

android:gravity="center"

android:text="List Name"

android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView

android:id="@+id/imageView3"

android:layout_width="32dp"

android:layout_height="32dp"

android:layout_weight="1"

android:gravity="right"

android:scaleType="fitEnd"

android:src="@drawable/next" />

</LinearLayout>

</LinearLayout>

网友答案:

Try changing your widget_info.xml to:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:initialLayout="@layout/layout_widget"
        android:minHeight="110dp"
        android:minWidth="250dp"
        android:updatePeriodMillis="180000">

</appwidget-provider>

And make sure your widget declares android:resource="@xml/widget_info" in your manifest.

分享给朋友:
您可能感兴趣的文章:
随机阅读: