我在查找 Android 4.2 中引入的锁屏小部件的参考资料时遇到了很多麻烦。
我创建了一个在启动器上运行良好的小部件,它的大小符合我的预期。但是,我已启用此小部件以显示在锁屏上,但垂直尺寸不正确。
根据http://developer.android.com/guide/topics/appwidgets/index.html#lockscreen如果您设置它将占用垂直可用的大小android:resizeMode="vertical"
如果小部件将自身标记为可垂直调整大小,则小部件高度在显示解锁 UI 的竖屏手机上显示为“小”。在所有其他情况下,小部件的大小以填充可用高度。
我还使用了http://developer.android.com/guide/practices/ui_guidelines/widget_design.html中描述的大小
瓷砖 > 尺寸
- 1 > 40dp
- 2 > 110dp
- 3 > 180dp
- 4 > 250dp
- … > …</li>
- n > 70 × n - 30
我已经设置了这个,并且似乎比“小”小部件还要小。基本上,有谁知道图像 1中的小部件有什么问题,它不会扩展?我的代码如下。
1)它在默认状态下的样子。
2) 在另一个屏幕上展开时的样子。
xml/clock_widget.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialKeyguardLayout="@layout/clock_widget"
android:initialLayout="@layout/clock_widget"
android:minHeight="110dp"
android:minWidth="180dp"
android:resizeMode="vertical"
android:updatePeriodMillis="1000"
android:widgetCategory="keyguard|home_screen" >
</appwidget-provider>
布局/clock_widget.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/clock_widget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/widget_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="36sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="36sp" />
<TextView
android:id="@+id/widget_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="36sp" />
</LinearLayout>
<TextView
android:id="@+id/widget_date"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>