Jowie Jowie - 2 months ago 16
Android Question

Android studio XML textview on an imageview

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

<ImageView
android:layout_width="433dp"
android:layout_height="210dp"
android:layout_marginTop="25dp"
android:id="@+id/imageView"
android:scaleType="fitXY"
android:contentDescription="@string/image_description" />

<TextView
android:id="@+id/item_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="@string/list_number_placeholder"
android:textColor="@color/bar_separator_color"
android:layout_centerInParent="true"
android:textSize="50dp"
android:gravity="center"
android:layout_marginLeft="85dp"
/>


I have a question i cant get the text on my imageview, i think its something with the layers. Please help me..

im btw a beginner in Android studio XD

Answer

you are using LinearLayout which stacks your view one by one, either in horizontal direction or vertical direction (Orientation).

So use RelativeLayout instead if you want views overlapping.

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

        <ImageView
            android:layout_width="433dp"
            android:layout_height="210dp"
            android:layout_marginTop="25dp"
            android:id="@+id/imageView"
            android:scaleType="fitXY"
            android:contentDescription="@string/image_description" />

        <TextView
            android:id="@+id/item_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:text="@string/list_number_placeholder"
            android:textColor="@color/bar_separator_color"
            android:layout_centerInParent="true"
            android:textSize="50dp"
            android:gravity="center"
            android:layout_marginLeft="85dp"
            />

</RelativeLayout>