-1

i want to implement a text view on the top of the image view where the user can define his own text of his own type and can save text on the top of the image view .can anyone help me with good tutorial? here is my Fullimage activity class

  public class FullImageActivity extends Activity {

   @Override
     public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fullimage);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    int position = i.getExtras().getInt("id");
    ImageAdapter imageAdapter = new ImageAdapter(this);

    ImageView imageView = (ImageView) findViewById(R.id.fullimage);
    imageView.setImageResource(imageAdapter.mThumbIds[position]);
  }

here is the basic example}

GOPATHI
  • 91
  • 1
  • 6

5 Answers5

2
< Relativelayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

  < ImageView
     android:id="@+id/image"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:src="@drawable/contact" />

 <TextView
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignBottom="@+id/image" />

 </Relativelayout >
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
1

you need to use the customviews.. use canvas to write text on image override onDraw() method

 @ Override
public void onDraw ( Canvas canvas ) {

    try {
        canvas.drawColor ( Color.BLACK ) ;
        bitmap = BitmapFactory.decodeResource ( getResources ( ) , ( R.drawable.background_image ) ) ;

        canvas.drawBitmap ( bitmap , 0 , 0 , null ) ;

        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        canvas.drawText("Text to be drwaw", my_txt_x_position, my_txt_y_position, paint);

    } catch ( Exception e ) {
        e.printStackTrace ( ) ;
    } catch ( Error e ) {
        e.printStackTrace ( ) ;
    }

}
Beginner
  • 1,414
  • 2
  • 21
  • 41
1

add this in your layout

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    android:src="@drawable/contact" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/image"
    android:background="#77000000"
    android:paddingBottom="14dip"
    android:paddingLeft="8dip"
    android:paddingTop="14dip"
    android:text="Load and user your OWN photos!"
    android:textColor="#FFFFFFFF"
    android:textSize="18sp" />

make sure it should be in tag RelativeLayout

swati srivastav
  • 635
  • 4
  • 15
0

I used Relative Layout to overlay the views.Try to use relative layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativelayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

    <TextView
        android:id="@+id/myImageViewText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/img_corct"
        android:layout_alignLeft="@+id/img_corct"
        android:layout_alignRight="@+id/img_corct"
        android:layout_alignTop="@+id/img_corct"
        android:text="Sample Text"
        android:textColor="#000000"
        android:textSize="24sp" />

</RelativeLayout>
Kalai.G
  • 1,610
  • 13
  • 22
0

What about just putting both of your views into one FrameLayout or RelativeLayout ?

There is an excellent tutorial by Romain Guy from the Android Team to achieve this result with a FrameLayout.

You could then replace (hide/show) your TextView by an EditText when the user hits the former. Or you could even display a dialog to allow the user to change the text.

ovmjm
  • 1,624
  • 12
  • 15