I want to overlay textview
on imageview
on android which I have done programatically. I also want that image should be able to zoom in and zoom out which also I am able to done. But I am stuck in a problem of placing text on image in such a way that while I zoom image then text should not zoom and it should stay on the same position on the image not on the screen.
OK, I created an XML layout that fits your needs. All you have to do is zoom in or out of the image.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="287dp"
android:layout_height="287dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Constant Text Overlay"
android:layout_gravity="center_horizontal|center_vertical"/>
<!-- Don't want it centered? Then change the layout gravity to fit your needs -->
</FrameLayout>
With this, you can easily modify the width and height of the ImageView and the TextView will remain in the center without getting larger or smaller.
I noticed that you took a programmatic solution, and you can easily look at how it is done via XML and convert that to code.
What is important here is that you have a container around your ImageView that wraps the content. Inside of that you have the ImageView of specified width/height, and a TextView that is centered horizontally and vertically in the container.
You can do whatever you want to do with the Image now, the text will remain untouched; just it will remain in the center
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