6

I want to display TextView after ImageView but right now Text is coming over Image on my Android screen.

layout:

<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"
tools:context="in.sitemakers.sitemakers.AboutFragment">

<ImageView
    android:id="@+id/about_image"
    android:src="@drawable/sitemakers_laptops"
    android:layout_width="match_parent"
    android:scaleType="fitXY"
    android:layout_height="420dp" />

<TextView
    android:layout_below="@+id/about_image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Site Makers is the web development company engage in the.."
    />

</FrameLayout>

Preview

Please see above screenshot and help me update my XML in such a way so that TextView will come after ImageView.

Amit Gupta
  • 2,771
  • 2
  • 17
  • 31

3 Answers3

7

Replace FrameLayout with LinearLayout or RelativeLayout because FrameLayout place view one over another

LinearLayout : Place child view in linear fashion , one after another either horizontally or vertically.

Note : Linear layout also let you allocate the available width and height among child views dynamically as per assigned weight property value.

RelativeLayout : A Layout where the positions of the children can be described in relation to each other or to the parent

There are many other ViewGroups you can use as per the instructions

Note : Don't use px instead use dp as android:layout_height="420dp" because px represent actual screen pixel which restrict to keep the same size of your views on large screen (views will be quite small) , as mentioned here with Density independence

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
1

You can use linearlayout with orientation="vertical" and Its really easy to implement.

Rohit S
  • 714
  • 5
  • 7
0

You can use LinearLayout or RelativeLayout

If You use LinearLayout So you can set orientation="vertical"

If You use RelativeLayout So you can use android:layout_below="@id/about_image" in Your TextView.

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

    <ImageView
        android:id="@+id/about_image"
        android:src="@drawable/sitemakers_laptops"
        android:layout_width="match_parent"
        android:scaleType="fitXY"
        android:layout_height="420px" />

    <TextView
        android:layout_below="@+id/about_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Site Makers is the web development company engage in the.."/>

    </LinearLayout>