soonmyeong2

make indicator in mainpage

package com.example.vip
import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.widget.ImageView
import android.widget.LinearLayout
class CircleIndicator: LinearLayout {
private var mContext: Context? = null
private var mDefaultCircle: Int = 0
private var mSelectCircle: Int = 0
private var imageDot: MutableList<ImageView> = mutableListOf()
// 4.5dp 를 픽셀 단위로 바꿉니다.
private val temp = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 4.5f, resources.displayMetrics)
constructor(context: Context) : super(context) {
mContext = context
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
mContext = context
}
/**
* 기본 점 생성
* @param count 점의 갯수
* @param defaultCircle 기본 점의 이미지
* @param selectCircle 선택된 점의 이미지
* @param position 선택된 점의 포지션
*/
fun createDotPanel(count: Int, defaultCircle: Int, selectCircle: Int, position: Int) {
this.removeAllViews()
mDefaultCircle = defaultCircle
mSelectCircle = selectCircle
for (i in 0 until count) {
imageDot.add(ImageView(mContext).apply { setPadding(temp.toInt(), 0, temp.toInt(), 0) })
this.addView(imageDot[i])
}
//인덱스 선택
selectDot(position)
}
/**
* 선택된 점 표시
* @param position
*/
fun selectDot(position: Int) {
for (i in imageDot.indices) {
if (i == position) {
imageDot[i].setImageResource(mSelectCircle)
} else {
imageDot[i].setImageResource(mDefaultCircle)
}
}
}
}
\ No newline at end of file
......@@ -177,7 +177,7 @@ class DetailActivity : AppCompatActivity() {
setSupportActionBar(toolbar)
// 2. 툴바 왼쪽 버튼 설정
supportActionBar!!.setDisplayHomeAsUpEnabled(true) // 왼쪽 버튼 사용 여부 true
supportActionBar!!.setDisplayHomeAsUpEnabled(false) // 왼쪽 버튼 사용 여부 true
supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정
supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기
......
......@@ -12,7 +12,9 @@ import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat.finishAffinity
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity
import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
......@@ -150,6 +152,25 @@ class SignInActivity : AppCompatActivity() {
val viewpageradapter = ViewPagerAdapter(this)
viewpager.adapter = viewpageradapter
viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
override fun onPageScrollStateChanged(p0: Int) {
}
override fun onPageScrolled(p0: Int, p1: Float, p2: Int) {
}
override fun onPageSelected(p0: Int) {
ciMainActivity.selectDot(p0)
}
})
//init indicator
ciMainActivity.createDotPanel(3, R.drawable.indicator_dot_off, R.drawable.indicator_dot_on, 0)
// 1. 툴바 사용 설정
setSupportActionBar(toolbar)
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#FFF"/>
<size
android:height="7dp"
android:width="7dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#29ABE2"/>
<size
android:height="7dp"
android:width="7dp"/>
</shape>
\ No newline at end of file
......@@ -34,24 +34,6 @@
android:src="@drawable/toolbar_logo" />
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="1"
android:gravity="top"
android:orientation="horizontal">
<androidx.viewpager.widget.ViewPager
android:id="@+id/welcomeViewPager"
android:layout_width="match_parent"
android:layout_height="262dp"
android:layout_gravity="top"
android:layout_weight="1">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
<!--
<LinearLayout
android:layout_width="match_parent"
......@@ -86,6 +68,30 @@
</LinearLayout>
-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.viewpager.widget.ViewPager
android:id="@+id/welcomeViewPager"
android:layout_width="match_parent"
android:layout_height="262dp"
android:layout_gravity="top"
android:layout_weight="1">
</androidx.viewpager.widget.ViewPager>
<com.example.vip.CircleIndicator
android:id="@+id/ciMainActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
......