Transparent View over ImageView

android:background="@color/transparent"

You can use the transparent color provided in android resources:

android:background="@android:color/transparent"

android:color="#80000000"  

<resources>
    <color name="transp">#80000000</color>
</resources>

myViewm.setBackgroundResource(R.color.trans);

This will give you a very dark shade of gray. Alpha value of 80 is translucent at best.


myView.getBackground().setAlpha(45);

You may not be using this correctly.


private ImageView bg;
MyView tV;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                 WindowManager.LayoutParams.FLAG_FULLSCREEN);

    tV = new MyView(this);

    setContentView(tV);
}

This basically replaces the View inflated from R.layout.activity_main(which contains the ImageView and other widgets) with MyView. I don't think this is quite what you want. Try the following:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/backgroundview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/space_bg"
        android:contentDescription="@string/desc" />

    <RelativeLayout 
        android:id="@+id/tileview"        
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/transparent" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/some_drawable_smaller_than_screen_size"
            android:layout_centerInParent="true" />

    </RelativeLayout>

</RelativeLayout>

How to inflate this xml:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                 WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);
}

id="@+id/tileview" will be transparent and over id="@+id/backgroundview".


android:alpha="0.5"

0.0 is totally transparent, 0.5 is medium transparent 1.0 is fully opaque transparent. **Here TextView is Transparent.

enter image description here.enter image description here

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

    <ImageView
        android:id="@+id/imageview_id"
        android:layout_width="match_parent"[![enter image description here][2]][2]
        android:layout_height="130dp"
        android:scaleType="centerCrop"
        android:src="@drawable/img3" />

    <TextView
        android:id="@+id/home_tvshow_textView_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:alpha="0.5"
        android:background="@color/red"
        android:gravity="center"
        android:text="Your String"
        android:textColor="@color/black"
        android:textSize="@dimen/sp_17"
        android:layout_marginTop="@dimen/dp_110"/>


</RelativeLayout>

  • Achieving with manual view

If you're using Relative Layout as parent tag in your layout.

You're layout should be like this..

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
.
.
.
    <View
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="#EBE9E9"
       android:id="@+id/hide_view"/>
</RelativeLayout>

In Your Activity

hide_view = findViewById(R.id.hide_view);
hide_view.setAlpha(0.5f);