GithubHelp home page GithubHelp logo

exp8's Introduction

Ex.No:8 To create a gallery control using android studio to display images or photos.

AIM:

To create a gallery control using android studio to display images or photos.

EQUIPMENTS REQUIRED:

Latest Version Android Studio

ALGORITHM:

Step 1: Open Android Studio and then click on File -> New -> New project.

Step 2: Then type the Application name as GalleryControl and click Next.

Step 3: Then select the Minimum SDK as shown below and click Next.

Step 4: Then select the Empty Activity and click Next. Finally click Finish.

Step 5: Design layout in activity_main.xml.

Step 6: Create a CustomizedGalleryAdapter file.

Step 7: Set the adapter for the gallery in the MainActivity file.

Step 8: Save and run the application.

PROGRAM:

/*
Program to print the text “GalleryControl”.
Developed by: A.Sanjay
Registeration Number : 212221040145
*/
XML FILE:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="36dp"
    app:layout_constraintBottom_toTopOf="@+id/languagesGallery"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.466"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:srcCompat="@tools:sample/avatars" />

<Gallery
    android:id="@+id/languagesGallery"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animationDuration="2000"
    android:padding="10dp"
    android:spacing="5dp"
    android:unselectedAlpha="50"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"></Gallery>

</androidx.constraintlayout.widget.ConstraintLayout>

MAIN CODE:

package com.example.galleryview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Gallery; import android.widget.ImageView;

public class MainActivity extends AppCompatActivity { Gallery simpleGallery; CustomizedGalleryAdapter customGalleryAdapter; ImageView selectedImageView; int[] images = {R.drawable.p1, R.drawable.p2,R.drawable.p3,R.drawable.p4}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); simpleGallery = (Gallery) findViewById(R.id.languagesGallery); selectedImageView = (ImageView) findViewById(R.id.imageView); customGalleryAdapter = new CustomizedGalleryAdapter(getApplicationContext(), images); simpleGallery.setAdapter(customGalleryAdapter); simpleGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectedImageView.setImageResource(images[position]); } }); } } CustomizedGalleryAdapter Code:

package com.example.galleryview;

import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView;

public class CustomizedGalleryAdapter extends BaseAdapter { private Context context; private int[] images; public CustomizedGalleryAdapter(Context c, int[] images) { context = c; this.images = images; } public int getCount() { return images.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(context); imageView.setImageResource(images[position]); imageView.setLayoutParams(new Gallery.LayoutParams(200, 200)); return imageView; } }

OUTPUT

241160595-f6eb297d-26cd-4fe4-9cb8-7370731ead7b 241160614-ea00c67a-447b-432e-8c88-084127cc32e5 241160633-75bf214c-ecc7-4795-9251-3bc5920ba0a8 241160678-2da801b4-f67d-4286-852b-46823d155006 241160655-8da0e4eb-31cb-4073-a2fd-216138cab42a

RESULT

Thus a Simple Android Application to create a gallery control using android studio to display images or photos is developed and executed successfully.

exp8's People

Contributors

militantvlr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.