Thursday 11 April 2013

How to put imageview on another imageview tranperent ?

Hello,

  Today I explain how to put ImageView on another ImageView as Transparent.

 Following is an xml file.

main.xml


<?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

     <ImageView       
android:id="@+id/first"       
android:layout_width="fill_parent"       
android:layout_height="fill_parent"       
android:src="@drawable/ic_launcher" >   
</ImageView>   

<ImageView       
android:id="@+id/second"       
android:layout_width="fill_parent"       
android:layout_height="fill_parent"
         android:background="@android:color/transparent"         android:src="@drawable/bg4" />
</FrameLayout>


 Following is JAVA file.

TransperentViewOnAnotherViewActivity.java

public class TransperentViewOnAnotherViewActivity extends Activity {

    /** Called when the activity is first created. */
    ImageView first, second;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        first = (ImageView) findViewById(R.id.first);
        second = (ImageView) findViewById(R.id.second);
        second.setAlpha(127);
    }

}



Description : Using setAlpha() we can Sets the opacity of the view. You can get more information from developer site.

Output :

No comments:

Post a Comment