Create an android application for a picture gallery which shows the image items in a horizontal scrolling list. Clicking on the image, it should show in the ImageView. Apply animation to the image to transits from one image to another. Use ImageSwitcher with gallery.

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="5"
    tools:context="com.example.krazz.colprac4.MainActivity">   <!-- write proper context-->


    <Gallery
        android:id="@+id/gal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"></Gallery>

    <ImageSwitcher
        android:id="@+id/imgsw"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3">

        <ImageView
            android:id="@+id/imgv"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </ImageSwitcher>

</LinearLayout>





MainActivity.java :

package com.example.krazz.colprac4; //keep your package as it is and copy paste from below

import android.app.Activity;
import android.content.Context;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;

public class MainActivity extends Activity implements ViewSwitcher.ViewFactory{


    ImageSwitcher imgsw;
    ImageView imgv;

    @Override
    @SuppressWarnings("deprecation")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Gallery g=(Gallery)findViewById(R.id.gal);
        g.setAdapter(new CustomGallery(this));
        imgsw=(ImageSwitcher)findViewById(R.id.imgsw);
        final int imgid[]={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.e,R.drawable.f};
        //change names of above images to those which you copy in the drawable folder
        imgv=(ImageView)findViewById(R.id.imgv);
        imgsw.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
        imgsw.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
        g.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                imgv.setImageResource(imgid[i]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

    }

    @Override
    public View makeView() {
        return null;
    }


    class CustomGallery extends BaseAdapter
    {

        Context context;
        int imgid[]={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.e,R.drawable.f};
        //change names of above images to those which you copy in the drawable folder
        CustomGallery(Context c)
        {
            context=c;
        }

        @Override
        public int getCount() {
            return imgid.length;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ImageView imageView;
            if(view==null)
            {
                imageView=new ImageView(context);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                //imageView.setLayoutParams(new Gallery.LayoutParams(150,120));
                imageView.setImageResource(imgid[i]);
            }
            else
            {
                imageView=(ImageView)view;
            }
            return imageView;
        }
    }
}


Output :