Alex Rivera | Logout

Set alpha on ImageView without setAlpha

Asked 2012-03-13T21:06:05.133
9

Can I programatically set the alpha of an ImageView without the need for being dependent on API level 11 where setAlpha was introduced?

Edit
Report

1 Answer

2

you can make a new layout with just ur image, set the alpha you need for the layout, set it as an overlay and inflate when you want.

LayoutInflater inflater = LayoutInflater.from(this);
        View overView = inflater.inflate(R.layout.myAlpahImageLayout, null);
        this.addContentView(overView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


<RelativeLayout 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"
    android:alpha="0.5"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/myImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/myImage1" />

</RelativeLayout>
answered 2013-01-11T01:37:37.600

Your Answer