Skip to content

Commit

Permalink
[maro/#13] feat : ViewPager Indicator, CircleIndicator, Auto Slide
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed Apr 20, 2024
1 parent 66d18d0 commit 3918c69
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
19 changes: 15 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
implementation("androidx.fragment:fragment-ktx:1.3.0")
implementation ("androidx.viewpager2:viewpager2:1.0.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation ("me.relex:circleindicator:2.1.6")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
Expand Down
29 changes: 29 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import androidx.viewpager2.widget.ViewPager2
import com.example.umc_6th.databinding.FragmentHomeBinding
import java.util.Timer
import java.util.TimerTask
import android.os.Handler
import android.os.Looper

class HomeFragment : Fragment() {

lateinit var binding : FragmentHomeBinding

private val timer = Timer()
private val handler = Handler(Looper.getMainLooper())

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -37,15 +43,38 @@ class HomeFragment : Fragment() {
val bannerAdapter = BannerVPAdapter(this)
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp2))

binding.homeBannerVp.adapter = bannerAdapter
binding.homeBannerVp.orientation = ViewPager2.ORIENTATION_HORIZONTAL

binding.homeBannerIndicator.setViewPager(binding.homeBannerVp)

autoSlide(bannerAdapter)

val pannelAdpater = PannelVpAdapter(this)
pannelAdpater.addFragment(PannelFragment(R.drawable.img_first_album_default))
pannelAdpater.addFragment(PannelFragment(R.drawable.img_first_album_default))

binding.homePannelBackgroundVp.adapter = pannelAdpater
binding.homePannelBackgroundVp.orientation = ViewPager2.ORIENTATION_HORIZONTAL

binding.homePannelIndicator.setViewPager(binding.homePannelBackgroundVp)

return binding.root
}

private fun autoSlide(adapter: BannerVPAdapter) {
timer.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
handler.post {
val nextItem = binding.homeBannerVp.currentItem + 1
if (nextItem < adapter.itemCount) {
binding.homeBannerVp.currentItem = nextItem
} else {
binding.homeBannerVp.currentItem = 0 // 순환
}
}
}
}, 3000, 3000)
}
}
23 changes: 23 additions & 0 deletions UMC_6th/app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<me.relex.circleindicator.CircleIndicator3
android:id="@+id/home_pannel_indicator"
android:layout_width="match_parent"
android:layout_height="32dp"
app:ci_drawable_unselected="@drawable/gray_radius"
app:ci_drawable="@drawable/blue_radius"
app:ci_animator="@animator/scale_with_alpha"
app:layout_constraintTop_toBottomOf="@id/home_pannel_background_vp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>


<ImageView
android:id="@+id/home_pannel_btn_nugu_iv"
android:layout_width="35dp"
Expand Down Expand Up @@ -352,6 +364,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/home_today_music_oversea_hs"/>

<me.relex.circleindicator.CircleIndicator3
android:id="@+id/home_banner_indicator"
android:layout_width="match_parent"
android:layout_height="32dp"
app:ci_drawable_unselected="@drawable/gray_radius"
app:ci_drawable="@drawable/blue_radius"
app:ci_animator="@animator/scale_with_alpha"
app:layout_constraintTop_toBottomOf="@id/home_banner_vp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<!-- <ImageView-->
<!-- android:id="@+id/home_banner_vp"-->
<!-- android:layout_width="match_parent"-->
Expand Down

0 comments on commit 3918c69

Please sign in to comment.