Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to programmatically resize a TextView inside a widget?

As a learning exercise, I'm working on a very simple native Android widget.

The widget has a RelativeLayout containing a single ImageView and a single TextView. The TextView is populated with a name pulled from a web service while the ImageView is populated with a url from the same.

The TextView is positioned like this: android:layout_toRightOf="@+id/image"

My basic issue is trying to get the TextView sized to fit the content in it. I've only been able to figure out how to provide an explicit or inherited width in the TextView layout xml.

What I'd really like is something like this:

enter image description here

It doesn't appear possible to get a handle to the TextView inside the RemoteView the widget is using so I don't seem to be able to resize it on the fly.

Is there a recommended way to achieve the above layout?

like image 827
Mark Biek Avatar asked Mar 26 '26 02:03

Mark Biek


2 Answers

TextView

android:layout_width="wrap_content"
android:layout_alignParentRight="true"

ImageView

android:layout_toLeftOf="@+id/lTextView"
like image 196
Pozzo Apps Avatar answered Mar 28 '26 15:03

Pozzo Apps


Like 0gravity suggested, android:layout_width = "wrap_content". Then use paddings to adjust the space around your text until it looks as desired.

like image 23
Michael Avatar answered Mar 28 '26 14:03

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!