Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set position of TextView in RemoteView during runtime

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?

like image 720
Oliver Avatar asked May 27 '11 14:05

Oliver


1 Answers

At the time of the answer, the RemoteViews API does not allow you to set translation or position

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)

like image 104
vadiole Avatar answered Oct 15 '22 21:10

vadiole