[英]Android Widget Wrong Size
I have an Android widget. 我有一个Android小部件。 I would like it to be 4 cells width and 2 cells height.
我希望它是4个单元格的宽度和2个单元格的高度。 Right now the size of the widget is 4 by 4 (for some reason).
现在,小部件的大小为4 x 4(由于某种原因)。 And the strange thing is that the content of the widget, ie 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).
因此,大多数主屏幕为空白,但我无法重新定位小部件的位置(似乎它占据了主屏幕上的所有4 x 4单元格)。 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?
为什么要花4乘4而不是4乘2?
App Widget layouts should be flexible, resizing to fit their parent container
应用窗口小部件的布局应灵活,可调整大小以适合其父容器
So, change your LinearLayout 因此,更改您的LinearLayout
android:layout_width="wrap_content"
android:layout_height="110dp"
to match parent size 匹配父母的大小
android:layout_width="match_parent"
android:layout_height="match_parent"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.