【问题标题】:Auto resize text in Widget using RemoteView使用 RemoteView 自动调整 Widget 中的文本大小
【发布时间】:2015-07-03 01:34:40
【问题描述】:

我尝试使用this example here (AutoResizeTextView)this example here (FontFitTextView) 来调整小部件中文本的大小。

我有一个更新小部件的BroadcastReceiver,在这个BroadcastReceiver 中我有以下内容。我构造了RemoteView

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
ComponentName thisWidget = new ComponentName(mContext, Widget.class);
RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.widget);

然后我设置变量之一:

//convert to Fahrenheit if Fahrenheit selected
views.setTextViewText(R.id.wTemperature, convertTemperature(parts[4]) + "\u00B0");

我已将我的 widget.xml 相应地调整为:

<uk.co.diong.weatherlive_ish.FontFitTextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textColor="#ffffff"
    android:textSize="29sp"
    android:textStyle="bold"
    android:gravity="center"
    android:text="Temp"
    android:id="@+id/wTemperature" />

但我的小部件现在声明 问题加载小部件,所以现在我想知道几个小时后,这是否适用于 RemoteViews?这两个类都扩展了 TextView 而不是 RemoteView。

编辑: LogCat 里面有这个:

04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method     android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 11389: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 11395: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.view.ViewGroup.onWindowSystemUiVisibilityChanged, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onWindowSystemUiVisibilityChanged
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 11397: Landroid/view/ViewGroup;.onWindowSystemUiVisibilityChanged (I)V
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0008
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 9075: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-22 17:38:13.213  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 11392: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish W/dalvikvm﹕ VFY: unable to resolve virtual method 409: Landroid/content/res/TypedArray;.getType (I)I
04-22 17:38:13.223  14405-14405/uk.co.diong.weatherlive_ish D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002

【问题讨论】:

  • 你试过了吗? Logcat 中的任何内容?
  • 是的,我已经尝试过了,我已经编辑了上面的内容并包含了 LogCat。

标签: android textview android-remoteview


【解决方案1】:

您无法在RemoteView 中加载自定义视图。

Android Doc 说,Widget 中只能加载少数 Layouts 和 Views。恐怕无法调整大小。

【讨论】:

    【解决方案2】:

    我不知道下面的答案是否正确,但请尝试一下

    问题可能是由 com.android.support:appcompat-v7:21.0.3 引起的,这是使用 Android 的新布局功能所需的主要依赖项。尝试回到 v7:20.0.0,这应该可以解决问题。

    从这里找到

    https://stackoverflow.com/a/27989207/3728591

    【讨论】:

    • 我确实更改了 build.gradle 并且所发生的只是带有这些错误的 logcat 已经消失,但是我得到了相同的结果 Problem Loading Widget 我已经尝试了 4 个小时,这让我很沮丧。
    • 检查下面的链接并在那里尝试一些建议的解决方案。 link
    • 我在 onEnabled 中创建了一个带有 Widget Loaded 的日志,并且我的 widget.java 似乎运行良好,就像在 onEnabled 中的日志 Widget Loaded 实际上显示在 LogCat 中并且没有其他消息,并且我在 LogCat 中处于详细模式。我还在onUpdated 中创建了一个日志,其中指出在小部件中输入了onUpdate
    猜你喜欢
    • 2018-03-10
    • 2014-09-25
    • 2020-04-16
    • 2011-02-28
    • 1970-01-01
    • 2014-05-04
    • 2013-06-14
    • 1970-01-01
    相关资源
    最近更新 更多