Search code examples
androidandroid-layoutandroid-linearlayout

Android ImageView with transparent title in botton of the layout


I have a layout with an imageview and a textview.

I would like to have something like this :

enter image description here

An imageview with a title but i would like that the layout of the title be transparent in order to show the imageview in background.

Here is the code of my layout :

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="230dp"
        android:layout_marginBottom="3dp" >

        <ImageView
            android:id="@+id/imgimg"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/ic_action_picture"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/titlenew"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="TextView"
            android:textColor="@color/blanc" />

    </RelativeLayout>

</LinearLayout>

Solution

  • try this

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="230dp"
        android:layout_marginBottom="3dp" >
    
        <ImageView
            android:id="@+id/imgimg"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_launcher" />
    
        <TextView
            android:id="@+id/titlenew"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#80000000"
            android:gravity="center"
            android:padding="5dp"
            android:text="TextView"
            android:textColor="#fff" />
    </RelativeLayout>
    

    enter image description here