wawanopoulos
wawanopoulos

Reputation: 9804

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>

Upvotes: 1

Views: 2654

Answers (4)

Ketan Ahir
Ketan Ahir

Reputation: 6738

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

Upvotes: 4

Linh Nguyen
Linh Nguyen

Reputation: 1264

Here you go :)

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


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

            <TextView
                android:id="@+id/titlenew"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:gravity="bottom" 
                android:paddingTop="5dp"
                android:paddingBottom="5dp"
                android:layout_gravity="bottom"
                android:background="#99000000"
                android:textColor="@color/blanc" />


    </FrameLayout>

Upvotes: 0

Sushil
Sushil

Reputation: 8488

You can add this to textview:

android:background="#00000000"

If you want to control transparency of backgrounf play with alpha value like this:

android:background="#CCFF0000"

Upvotes: 0

kriomant
kriomant

Reputation: 2326

Try to set android:background="@android:color/transparent" on TextView.

Upvotes: 1

Related Questions