-1

i'm at learning stage of android. i want to set TextView on ImageView. i'm not getting point. I'll be thankful. Here's is my XML code.

<LinearLayout 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"
    >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="380dp"       
        android:adjustViewBounds="true"    
        android:scaleType="fitCenter"
        android:background="@drawable/wf" />


    <TextView
   // what should i add here so that it can be visible on image view//
     />

</LinearLayout>
hamza
  • 31
  • 1
  • 7
  • Do you mean you want to put a TextView in fromt of an ImageView? You can't do this simply with a LinearLayout because this puts all views in a line side by side. – Sound Conception Nov 09 '13 at 22:50
  • This does not make sense. A view cannot be both a textview and an imageview. If you want to combine views, you can use a viewgroup. – wvdz Nov 09 '13 at 22:51
  • not in front of image view while i want to set TextView on ImageView...? – hamza Nov 09 '13 at 23:01
  • can you be more specific? – Emmanuel Nov 09 '13 at 23:18
  • i have added a picture through ImageView. now i want some text on same picture which will be randomly change...how can i add/set TextView over said picture....??hope u got it – hamza Nov 09 '13 at 23:27
  • possible duplicate of [Adding text to ImageView in Android](http://stackoverflow.com/questions/3404582/adding-text-to-imageview-in-android) – Tobias Nov 09 '13 at 23:32
  • `FrameLayout` enables you to overlay views. – Simon Nov 09 '13 at 23:35
  • Simon, can you write some code for me...i'll be thankful to you dear – hamza Nov 09 '13 at 23:41
  • Sorry, but no. StackOverflow doesn't work like that. You ask a question, people answer it (if it's on topic). There are hundreds of tutorials on the web, all easily found with Google. – Simon Nov 09 '13 at 23:49
  • Simon, Thanks for your suggestion..i've used FrameLayout as per your suggestion so finally got the point..Sorry if u did mind...Actually i'm very very beginner..anyway thanks for your cooperation.. – hamza Nov 09 '13 at 23:55

4 Answers4

1

Thanks to all, Finally i got solution. i used FrameLayout to handle it.

Here is the code

<FrameLayout 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"
    >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="380dp"       
        android:adjustViewBounds="true"    
        android:scaleType="fitCenter"
        android:background="@drawable/wf" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="8"
        android:textSize="100sp"
        android:layout_marginTop="120dp"
        android:layout_marginLeft="160dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</FrameLayout>
vgonisanz
  • 11,831
  • 13
  • 78
  • 130
hamza
  • 31
  • 1
  • 7
0

I think what you want is something like a photo caption therefore the Best way you can achieve that is by using a relative layout and your .xml layout would look like:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="69dp"/>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:text="TextView" />

Take note of the property of the textView

android:layout_below="@+id/imageView1"

That is the key. If for any reason you prefer a linearlayout as the main layout , you can nest a relative layout in a table -row (or another linear layout) which is nested in the main linear layout

i hope that isnt complicating

PS:this is a beginner's advice

theanimashaun
  • 306
  • 1
  • 2
  • 12
0

You can also use RelativeLayout as a parent, ImageView as the first child element and TextView as the second child element.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
rohith
  • 207
  • 2
  • 9
0

You can use a RelativeLayout like this :

    <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"
    >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="380dp"       
        android:adjustViewBounds="true"    
        android:scaleType="fitCenter"
        android:background="@drawable/wf" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       />

</RelativeLayout>
Jéwôm'
  • 3,753
  • 5
  • 40
  • 73