问题
I have a widget whose xml layout is simple: an ImageView
and a TextView
.
I can hardcode the rotation of the TextView
in the xml by using android:rotation
.
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.
But when the TextView
is buried within a RemoteViews
, you have to call the methods indirectly, like setTextViewText()
and setTextViewTextSize()
.
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()
.
OK to the question....
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.
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.
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
.
Any ideas?
Thanks!
回答1:
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()
.
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.
来源:https://stackoverflow.com/questions/28031296/setrotation-of-textview-in-remoteviews-app-widget