Using FrameLayout : FrameLayout « UI « Android






Using FrameLayout

 

package app.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class Test extends Activity{
  private ImageView one = null;
  private ImageView two = null;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      one = (ImageView)findViewById(R.id.oneImgView);
      two = (ImageView)findViewById(R.id.twoImgView);

      one.setOnClickListener(new OnClickListener(){

        public void onClick(View view) {
              two.setVisibility(View.VISIBLE);

              view.setVisibility(View.GONE);
          }});

      two.setOnClickListener(new OnClickListener(){

          public void onClick(View view) {
              one.setVisibility(View.VISIBLE);

              view.setVisibility(View.GONE);
          }});
  }
}

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

    <ImageView
        android:id="@+id/oneImgView" android:src="@drawable/icon"
        android:scaleType="fitCenter"
        android:layout_width="fill_parent"  android:layout_height="fill_parent"/>
    <ImageView
        android:id="@+id/twoImgView" android:src="@drawable/icon"
        android:scaleType="fitCenter"
        android:layout_width="fill_parent"  android:layout_height="fill_parent"
        android:visibility="gone" />

</FrameLayout>

   
  








Related examples in the same category