Android Studio Image Switcher
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:padding="16dp"
android:layout_height="match_parent"
tools:context=".design12part15">
<ImageSwitcher
android:id="@+id/imageSwitcher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/bacck"/>
<Button
android:id="@+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="@string/nexxt"
android:layout_alignParentRight="true"
tools:ignore="RelativeOverlap" />
</RelativeLayout>
Android Studio Design Animation
Main_activity.kt
package com.designapp
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageSwitcher
import android.widget.ImageView
class design12part15 : AppCompatActivity() {
lateinit var imageSwitcher: ImageSwitcher
lateinit var bntNext : Button
lateinit var bntBack : Button
lateinit var arrImage : IntArray
var position : Int = -1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_design12part15)
imageSwitcher = findViewById(R.id.imageSwitcher)
bntBack = findViewById(R.id.backButton)
bntNext = findViewById(R.id.nextButton)
arrImage = intArrayOf(R.drawable.downloadicon, R.drawable.bitcoin, R.drawable.error,R.drawable.book,R.drawable.bug)
imageSwitcher.setFactory {
val imageView = ImageView(applicationContext)
imageView.scaleType = ImageView.ScaleType.FIT_CENTER
imageView
}
bntBack.setOnClickListener{
if(position>0)
{
position-=1
imageSwitcher.setImageResource(arrImage[position])
}
}
bntNext.setOnClickListener{
if(position<arrImage.size-1)
{
position+=1
imageSwitcher.setImageResource(arrImage[position])
}
}
}
}
Android Studio Design Animation
0 Response to "Android Studio Image Switcher"
Post a Comment