【问题标题】:Lockscreen Widget is too Small锁屏小部件太小
【发布时间】: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?

标签: android android-widget


【解决方案1】:

看起来这只发生在模拟器中。在真实硬件上进行测试可以正常工作。

【讨论】:

  • 好吧,我在带有我的小部件的 Genymotion 虚拟设备中看到了这个问题,并询问了一个拥有类似配置的智能手机的人,问题仍然存在。当您说“真正的硬件”时,您指的是哪部手机?
  • 它在 Galaxy Nexus、Nexus 4 和 Nexus 7 下运行良好。它不适用于配置 Galaxy Nexus 的模拟器
  • 奇怪...所有这些设备都带有库存启动器。您是说您的小部件一直看起来像图 2 中的小部件吗? AFAIK 纵向手机上的初始显示很小,一旦你向下滑动锁,它就会展开
  • 该小部件的大小与图 2 中的一样。问题是它应该是图 2 中的大小,但由于某种原因它在模拟器中被切断了,所以我只是在电话。
猜你喜欢
  • 2022-09-27
  • 1970-01-01
  • 1970-01-01
  • 2023-01-26
  • 1970-01-01
  • 2017-10-22
  • 2022-11-24
  • 1970-01-01
  • 2013-01-15
相关资源
最近更新 更多