使用RemoteView

时间:2015-04-24 12:30:43

标签: android textview android-remoteview

我尝试使用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

2 个答案:

答案 0 :(得分:0)

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

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

从这里找到

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

答案 1 :(得分:0)

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

Android Doc说,在Widget中只能加载少量布局和视图。我担心,不可能重新调整大小。