Dear all, I am trying to set the position of a TextView within an appwidget.
Basically, the direct access to properties af the TextView works:
myRemoteView.setTextColor(R.id.myTextView, Color.WHITE); //works
Also indirectly, I can access the TextView properties:
myRemoteView.setInt(R.id.myTextView, "setTextColor", Color.BLUE); // works
And setting float values also works:
myRemoteView.setFloat(R.id.myTextView, "setTextSize", 25); // works
Now I'm trying to shift the x position of the TextView by 5 pixels:
myRemoteView.setFloat(R.id.myTextView, "setTranslationX", 5); // does not work
myRemoteView.setFloat(R.id.myTextView, "setX", 5); // does not work
myRemoteView.setInt(R.id.myTextView, "setLeft", 5); // does not work
I tried FrameLayout and RelativeLayout, and also AbsoluteLayout (depreciated). Nothing works. But there must be a way to do that. Can you please help?
However, you can achieve the desired effect by setting the padding for the parent of your TextView
RemoteViews#setViewPadding(int, int, int, int, int, int)
Or, since API 31, you can also set the margin for your TextView
RemoteViews#setViewLayoutMargin(int, int, float, int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With