RemoteViews中的TextView的setRotation(应用程序小部件) [英] setRotation of TextView in RemoteViews (app widget)

查看:76
本文介绍了RemoteViews中的TextView的setRotation(应用程序小部件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小部件,其xml布局很简单: ImageView TextView .

I have a widget whose xml layout is simple: an ImageView and a TextView.

我可以使用 android:rotation 在xml中对 TextView 的旋转进行硬编码.

I can hardcode the rotation of the TextView in the xml by using android:rotation.

但是,我希望能够以编程方式设置 TextView 的旋转度.似乎 View 具有 setRotation()方法,所以 TextView 将继承此方法,从而使正常"的可以使用此方法以编程方式旋转TextView.

However I want to be able to set the rotation of the TextView programmatically. It seems that a View has a setRotation() method, so the TextView will inherit this method, such that a "normal" TextView can be rotated programmatically used this method.

但是,当 TextView 埋在 RemoteViews 中时,您必须间接调用方法,例如 setTextViewText()setTextViewTextSize().

But when the TextView is buried within a RemoteViews, you have to call the methods indirectly, like setTextViewText() and setTextViewTextSize().

似乎还可以调用常规的 setFloat(int viewId,String methodName,float value)来设置任何 methodName 的值,因此您可以设置文本大小也可以通过将"setTextSize" 传递给 setFloat().

And it also seems that you can call the general setFloat(int viewId, String methodName, float value) to set the value of any methodName, so you can set text size also via passing "setTextSize" to setFloat().

确定问题....

由于 RemoteViews 中没有 setTextViewRotation()方法,我认为我需要使用 setFloat(viewId,"setRotation",值).

Since there isn't a setTextViewRotation() method in RemoteViews, I figure I need to call that indirectly using setFloat(viewId, "setRotation", value).

但是,当我尝试这样做时,我的窗口小部件仅显示问题正在加载窗口小部件"消息框.

But when I try that, my widget just shows a "Problem Loading Widget" message box.

它与例如 setFloat(viewId,"setTextSize",value)来更改文本大小,因此我处于正确的轨道上,但不适用于同一代码中的 setRotation 放在我的代码中.

It works with e.g. setFloat(viewId, "setTextSize", value) to change the text size, so I'm on the right track, but it doesn't work for setRotation in the same place in my code.

我猜测是因为 setRotation 是继承的方法(来自 View ),而不是 TextView 本身的方法,但是对于如何旋转 TextView .

I'm guessing that it's because setRotation is an inherited method (from View), rather than a method of TextView itself, but it leaves me slightly stuck as to how to rotation my TextView.

有什么想法吗?

谢谢!

推荐答案

崩溃的原因是因为 setRotation()中没有 @RemotableViewMethod 批注 Android源代码,因此无法使用 setFloat()进行设置.

The reason why you are crashing is because setRotation() does not have the @RemotableViewMethod annotation in the Android source code, and therefore it cannot be set using setFloat().

我不知道有任何方法可以在应用程序小部件中动态更改 View 的旋转属性.一种解决方法是通过布局文件的N个版本支持N个旋转,每个版本都有一个硬编码的 android:rotation 值.

I am not aware of any way for you to change the rotation property of a View dynamically in an app widget. One workaround is to support N rotations via N versions of your layout file, each of which has a hardcoded android:rotation value.

这篇关于RemoteViews中的TextView的setRotation(应用程序小部件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆