【发布时间】:2012-11-28 00:54:11
【问题描述】:
我在查找 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
- ……>……
- n > 70 × n − 30
我已经设置了这个,并且看起来比“小”小部件还要小。基本上,有谁知道 image 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>
layout/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>
【问题讨论】:
-
您是否尝试将 minHeight 添加到根 LinearLayout?