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!
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.
Related
I am trying to change line count and TextSize in my text view on SmartEyeglass dynamically. I am calling showLayout() in my ControlExtension to show the layout on the glasses and then sendText() when my text changes. But I don't know how I can send layout instructions like setTextSize for example. or auto calling setMovementMethod() on the TextView to auto scroll down.
My only idea for those dynamic layout changes would be to create the whole layout in my ControlExtension, edit and render it there and send it as bitmap to the glasses as it changes . But they state in their documentation you shouldn't do it in the new API (4) and use the layout functions instead (showlayout and sendText)
Has anybody found a way to send dynamic layout information to the glasses?
Your idea is the right way to go. To change the text size or position dynamically you will need to create your layout in code and then call showBitmap() to redraw the layout each time.
Is there any (even if infinitesimal) memory/speed advantage if I use a DrawableLeft property of a TextLabel to show a image beside text instead of using a two objects (ImageView and TextLabel) adjusted next to next in a layout.
DrawableLeft solution would use just one object or widget, while the other one takes probaly three, as it may need a container to envelop image and text object. I would go for the one object solution, if it does job properly, as it would be more efficient both memory and speed wise.
So I can pass a custom View to the setContentView() and it fills the users screen by default(right?), but if I define a TextField within my custom views constructor it won't display. Even if I change my custom View to a custom ViewGroup and use its addView() method.
So what am I missing here?
Also, whats the equivalent of System.out.println() in android to get some feedback?
for print statements, used Log.d("Name of the filter", "Text to be printed here"). Also, why aren't you defining your view in an XML file and adding the textview inside there? it is usually not a good idea to use addview because it makes laying things out more difficult (not as many options for location and size, etc.)
I am new in android and facing the problem to get the maximum width of the multiline TextView.
I used textview.getWidth() and textview.getMeasuredWidth() but both gives garbage value.
I used also textview.length(), but retuns zero.
Please note that i have not set the maximum width of the TextView.I want to get it runtime.
TextView_name.setLayoutParams(new LayoutParams(250,LayoutParams.WRAP_CONTENT));
by using the above code we can set the width for textview dynamically
I would try to use getWidth(). If you want to do that though, you have to be careful when you call it. It only makes sense after the view hierarchy is laid out. That means that trying to check onCreate, onStart or even onResume will probably not get the results that you want. As an experiment, you can call it in a click handler of a button and you should see the expected value correctly being returned. I can't really say any more about where you should get it without knowing what you want to use it for.
While I'm developing a custom widget by using TextView widget, this question comes up to my mind.
When mText(member variable of TextView) is displayed, actually?
I have thought that, just like other widgets, if I override the onDraw method in the custom widget, which is derived from TextView, I can draw mText as I want.
But, it's not true.
I'm reviewing Android Widget source, and then I realized that mText is not displayed while onDraw is called, definitely.
Is there someone who knows about it?
take a look at protected makeNewLayout()