Created
November 8, 2019 11:55
-
-
Save john-lorrenz/385b07011d1b49da4dfbe02fab2dd0c2 to your computer and use it in GitHub Desktop.
View Page - Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<androidx.viewpager.widget.ViewPager | |
android:id="@+id/pager" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
var adapter = ViewPagerAdapter(this) | |
pager.adapter = adapter | |
} | |
internal inner class ViewPagerAdapter(val context: Context) : PagerAdapter() { | |
val Image = arrayOf(R.drawable.ic_android_black_24dp , R.drawable.ic_android_black_24dp) | |
override fun isViewFromObject(view: View, `object`: Any): Boolean { | |
return view === `object` | |
} | |
override fun getCount(): Int { | |
return Image.size | |
} | |
override fun instantiateItem(container: ViewGroup, position: Int): Any { | |
val imageView = ImageView(context) | |
imageView.setImageResource(Image[position]) | |
container.addView(imageView, 0) | |
return imageView | |
} | |
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) { | |
container.removeView(`object` as View) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment