신기성

viewpager demo create

......@@ -3,10 +3,12 @@ package com.example.vip
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.viewpager.widget.ViewPager
import kotlinx.android.synthetic.main.activity_signin.*
class SignInActivity : AppCompatActivity() {
internal lateinit var viewpager : ViewPager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_signin)
......@@ -27,6 +29,9 @@ class SignInActivity : AppCompatActivity() {
val adapter = PolicyFieldAdapter(policyFieldList)
policyFieldRecyclerView.adapter = adapter
viewpager=findViewById(R.id.viewpager) as ViewPager
val viewpageradapter = ViewPagerAdapter(this)
viewpager.adapter=viewpageradapter
}
......
package com.example.vip
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import androidx.viewpager.widget.ViewPager
class ViewPagerAdapter(private val context : Context) : PagerAdapter() {
private var layoutInflater : LayoutInflater? = null
val Image = arrayOf(
R.drawable.image01,
R.drawable.image02,
R.drawable.image03
)
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 {
layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val v = layoutInflater!!.inflate(R.layout.viewpager_activity, null)
val image = v.findViewById<View>(R.id.imageview) as ImageView
image.setImageResource(Image[position])
val vp = container as ViewPager
vp.addView(v , 0)
return v
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
val vp = container as ViewPager
val v = `object` as View
vp.removeView(v)
}
}
\ No newline at end of file
......@@ -19,11 +19,16 @@
android:layout_height="50dp"
android:text="로고 및 검색창" />
<TextView
android:id="@+id/space_rollingBanner"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="롤링배너창" />
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="436dp"
android:layout_height="220dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp">
</androidx.viewpager.widget.ViewPager>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/policyFieldRecyclerView"
......
<?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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />
</LinearLayout>
\ No newline at end of file