0

This code is not working properly, the TextView should appear over the ImageView, please tell me where I am wrong. I am just a beginner, so sorry for any silly questions.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Memorable Shaadi"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold|italic" />

    <ImageView
        android:id="@+id/main_img"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="@drawable/main_img" />
</RelativeLayout>

</RelativeLayout>
2
  • 1
    Why did u fix the size of the ImageView.? Can you post your designing screen shot?
    – Saritha G
    Aug 7, 2015 at 10:01
  • my problem is solved, thanks for replying Aug 8, 2015 at 18:22

4 Answers 4

0

try this

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp">



<ImageView
    android:id="@+id/main_img"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:background="@drawable/main_img" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:text="Memorable Shaadi"
    android:textColor="#fff"
    android:textSize="20sp"
    android:textStyle="bold|italic" />
</RelativeLayout>

inter-change your textview and imageview

0
0

Your problem its with the order you add views to RelativeLayout. Think about it as layers. If you want the TextView on the Top, the last view you should add is the TextView.

Try like this:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">

    <ImageView
        android:id="@+id/main_img"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="@drawable/main_img" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Memorable Shaadi"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold|italic" />
</RelativeLayout>
0
0

if you want to add any component below another in relative layout, you have to declare android:layout_below="@id/idOfTheComponentAbove"

while in linear layout you have to place them in order accordingly

0

you can put imageview and textview in a linearlayout and set its orientation to verical

<LinearLayout
    android:id="@+id/otpView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     >

     <TextView 
         android:id="@+id/helpText"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/text_otp_help"
         android:layout_marginTop="10dp"
         android:textColor="@color/white"
         android:textSize="15sp"
         android:layout_gravity="center_horizontal"
         />
         <ImageView
            android:id="@+id/imageViewMessageIcon"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/message_icon"
            android:src="@drawable/icon_mark" />

</LinearLayout>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.