0

我尝试使用此处的示例(AutoResizeTextView)此处的示例(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
4

2 回答 2

1

您不能在RemoteView.

Android Doc说,Widget 中只能加载少数 Layouts 和 Views。恐怕,调整大小是不可能的。

于 2018-06-08T08:29:35.583 回答
0

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

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

从这里找到

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

于 2015-04-24T13:09:30.917 回答