[go: up one dir, main page]

0% found this document useful (0 votes)
19 views5 pages

Practical No 3

The document contains an XML layout for an Android application with a ViewFlipper that displays two images and buttons for navigating between them. The MainActivity class in Kotlin initializes the ViewFlipper and sets up click listeners for 'Previous' and 'Next' buttons to control the image display. This setup allows users to flip through images in the application interface.

Uploaded by

pandeydimple422
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Practical No 3

The document contains an XML layout for an Android application with a ViewFlipper that displays two images and buttons for navigating between them. The MainActivity class in Kotlin initializes the ViewFlipper and sets up click listeners for 'Previous' and 'Next' buttons to control the image display. This setup allows users to flip through images in the application interface.

Uploaded by

pandeydimple422
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical no 3

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<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"

tools:context=".MainActivity">

<ViewFlipper

android:id="@+id/idViewFlipper"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_above="@id/idLLBtn"

android:inAnimation="@android:anim/slide_out_right"

android:outAnimation="@android:anim/slide_in_left">

<ImageView

android:layout_width="200dp"

android:layout_height="200dp"

android:layout_gravity="center"

android:padding="10dp"

android:src="@drawable/android" />

<ImageView

android:layout_width="200dp"

android:layout_height="200dp"
android:layout_gravity="center"

android:padding="10dp"

android:src="@drawable/windows" />

</ViewFlipper>

<LinearLayout

android:id="@+id/idLLBtn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:orientation="horizontal"

android:padding="4dp"

android:weightSum="4">

<Button

android:id="@+id/idBtnPrev"

android:layout_width="70dp"

android:layout_height="wrap_content"

android:layout_margin="5dp"

android:layout_weight="1"

android:text="Previous"

android:textAllCaps="false" />

<View

android:layout_width="0dp"

android:layout_height="0dp"

android:layout_weight="2" />

<Button

android:id="@+id/idBtnNext"
android:layout_width="70dp"

android:layout_height="wrap_content"

android:layout_margin="5dp"

android:layout_weight="1"

android:text="Next"

android:textAllCaps="false" />

</LinearLayout>

</RelativeLayout>

MainActivity.kt
package com.example.imageflipper

import androidx.appcompat.app.AppCompatActivity

import android.content.Intent

import android.net.Uri
import android.os.Bundle

import android.widget.Button

import android.widget.ViewFlipper

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

// initializing variables of view flipper

// and button with their ids.

val viewFlipper = findViewById<ViewFlipper>(R.id.idViewFlipper)

val prevBtn = findViewById<Button>(R.id.idBtnPrev)

val nextBtn = findViewById<Button>(R.id.idBtnNext)

// adding on click listener

// for our previous button.

prevBtn.setOnClickListener {

// on below line we are simply calling

// view flipper to show previous screen.

viewFlipper.showPrevious()

// adding on click listener

// for our next button.

nextBtn.setOnClickListener {

// on below line we are simply calling

// view flipper to show next screen.

viewFlipper.showNext()

}
}

OUTPUT

You might also like