user2550055
user2550055

Reputation: 49

how to "paste" some text on a imageview in Android?

I have an android project in which I use the camera and save tho photo in a imageView. So, I want to paste some text over this imageView. It's possible ??

Upvotes: 0

Views: 226

Answers (4)

Yuva Raj
Yuva Raj

Reputation: 3881

Follow these steps :

Step 1 : First Change the layout to RelativeLayout

Step 2 : Click and drag the imageview button inside your workspace and select the image you have stored in your drawable folder.

Step 3 : Choose TextView and drag it into your centre of the image. (Rightclick-EditText-Change into ur desired Text).

You can also use textStyle or textSize to make the text as big and for formatting.

Here is the simple sample code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/sm" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="148dp"
    android:textStyle="bold"
    android:text="Here is my text " />

</RelativeLayout>

Result :

enter image description here

Upvotes: 0

ridoy
ridoy

Reputation: 6332

Write something like this inside your RelativeLayout:

<ImageView
    android:id="@+id/myImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/imageSouce" />

<TextView
    android:id="@+id/textview1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textview1"
    android:layout_alignTop="@+id/textview1"
    android:layout_alignRight="@+id/textview1"
    android:layout_alignBottom="@+id/textview1"
    android:layout_margin="1dp"
    android:gravity="center"
    android:text="Hello"
    android:textColor="#000000" />

Or, Want to do it programmatically?Then follow..

Upvotes: 1

Uma
Uma

Reputation: 492

Use TextView and set the image background to the text view.

or

If you want to use image view then create TextView and place both TextView & ImageView in a RelativeLayout.

Upvotes: 0

techi.services
techi.services

Reputation: 8533

Create a RelativeLayout or FrameLayout containing your ImageView and a TextView. The TextView will appear over the ImageView.

Upvotes: 0

Related Questions