Showing
6 changed files
with
133 additions
and
11 deletions
1 | +package com.example.vip | ||
2 | + | ||
3 | +import android.content.Context | ||
4 | +import android.util.AttributeSet | ||
5 | +import android.util.TypedValue | ||
6 | +import android.widget.ImageView | ||
7 | +import android.widget.LinearLayout | ||
8 | + | ||
9 | +class CircleIndicator: LinearLayout { | ||
10 | + | ||
11 | + private var mContext: Context? = null | ||
12 | + | ||
13 | + private var mDefaultCircle: Int = 0 | ||
14 | + private var mSelectCircle: Int = 0 | ||
15 | + | ||
16 | + private var imageDot: MutableList<ImageView> = mutableListOf() | ||
17 | + | ||
18 | + // 4.5dp 를 픽셀 단위로 바꿉니다. | ||
19 | + private val temp = TypedValue.applyDimension( | ||
20 | + TypedValue.COMPLEX_UNIT_DIP, 4.5f, resources.displayMetrics) | ||
21 | + | ||
22 | + constructor(context: Context) : super(context) { | ||
23 | + mContext = context | ||
24 | + } | ||
25 | + | ||
26 | + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | ||
27 | + mContext = context | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * 기본 점 생성 | ||
32 | + * @param count 점의 갯수 | ||
33 | + * @param defaultCircle 기본 점의 이미지 | ||
34 | + * @param selectCircle 선택된 점의 이미지 | ||
35 | + * @param position 선택된 점의 포지션 | ||
36 | + */ | ||
37 | + fun createDotPanel(count: Int, defaultCircle: Int, selectCircle: Int, position: Int) { | ||
38 | + | ||
39 | + this.removeAllViews() | ||
40 | + | ||
41 | + mDefaultCircle = defaultCircle | ||
42 | + mSelectCircle = selectCircle | ||
43 | + | ||
44 | + for (i in 0 until count) { | ||
45 | + imageDot.add(ImageView(mContext).apply { setPadding(temp.toInt(), 0, temp.toInt(), 0) }) | ||
46 | + this.addView(imageDot[i]) | ||
47 | + } | ||
48 | + //인덱스 선택 | ||
49 | + selectDot(position) | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * 선택된 점 표시 | ||
54 | + * @param position | ||
55 | + */ | ||
56 | + fun selectDot(position: Int) { | ||
57 | + for (i in imageDot.indices) { | ||
58 | + if (i == position) { | ||
59 | + imageDot[i].setImageResource(mSelectCircle) | ||
60 | + } else { | ||
61 | + imageDot[i].setImageResource(mDefaultCircle) | ||
62 | + } | ||
63 | + } | ||
64 | + } | ||
65 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -177,7 +177,7 @@ class DetailActivity : AppCompatActivity() { | ... | @@ -177,7 +177,7 @@ class DetailActivity : AppCompatActivity() { |
177 | setSupportActionBar(toolbar) | 177 | setSupportActionBar(toolbar) |
178 | 178 | ||
179 | // 2. 툴바 왼쪽 버튼 설정 | 179 | // 2. 툴바 왼쪽 버튼 설정 |
180 | - supportActionBar!!.setDisplayHomeAsUpEnabled(true) // 왼쪽 버튼 사용 여부 true | 180 | + supportActionBar!!.setDisplayHomeAsUpEnabled(false) // 왼쪽 버튼 사용 여부 true |
181 | supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정 | 181 | supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정 |
182 | supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기 | 182 | supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기 |
183 | 183 | ... | ... |
... | @@ -12,7 +12,9 @@ import android.widget.Toast | ... | @@ -12,7 +12,9 @@ import android.widget.Toast |
12 | import androidx.appcompat.app.ActionBar | 12 | import androidx.appcompat.app.ActionBar |
13 | import androidx.appcompat.app.AlertDialog | 13 | import androidx.appcompat.app.AlertDialog |
14 | import androidx.appcompat.app.AppCompatActivity | 14 | import androidx.appcompat.app.AppCompatActivity |
15 | +import androidx.core.app.ActivityCompat.finishAffinity | ||
15 | import androidx.core.content.ContextCompat | 16 | import androidx.core.content.ContextCompat |
17 | +import androidx.core.content.ContextCompat.startActivity | ||
16 | import androidx.viewpager.widget.ViewPager | 18 | import androidx.viewpager.widget.ViewPager |
17 | import com.google.android.material.bottomnavigation.BottomNavigationView | 19 | import com.google.android.material.bottomnavigation.BottomNavigationView |
18 | import com.google.android.material.snackbar.Snackbar | 20 | import com.google.android.material.snackbar.Snackbar |
... | @@ -150,6 +152,25 @@ class SignInActivity : AppCompatActivity() { | ... | @@ -150,6 +152,25 @@ class SignInActivity : AppCompatActivity() { |
150 | val viewpageradapter = ViewPagerAdapter(this) | 152 | val viewpageradapter = ViewPagerAdapter(this) |
151 | viewpager.adapter = viewpageradapter | 153 | viewpager.adapter = viewpageradapter |
152 | 154 | ||
155 | + | ||
156 | + viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{ | ||
157 | + override fun onPageScrollStateChanged(p0: Int) { | ||
158 | + | ||
159 | + } | ||
160 | + | ||
161 | + override fun onPageScrolled(p0: Int, p1: Float, p2: Int) { | ||
162 | + | ||
163 | + } | ||
164 | + | ||
165 | + override fun onPageSelected(p0: Int) { | ||
166 | + ciMainActivity.selectDot(p0) | ||
167 | + } | ||
168 | + | ||
169 | + }) | ||
170 | + | ||
171 | + //init indicator | ||
172 | + ciMainActivity.createDotPanel(3, R.drawable.indicator_dot_off, R.drawable.indicator_dot_on, 0) | ||
173 | + | ||
153 | // 1. 툴바 사용 설정 | 174 | // 1. 툴바 사용 설정 |
154 | setSupportActionBar(toolbar) | 175 | setSupportActionBar(toolbar) |
155 | 176 | ... | ... |
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + android:shape="oval"> | ||
4 | + <solid | ||
5 | + android:color="#FFF"/> | ||
6 | + | ||
7 | + <size | ||
8 | + android:height="7dp" | ||
9 | + android:width="7dp"/> | ||
10 | +</shape> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + android:shape="oval"> | ||
4 | + | ||
5 | + <solid | ||
6 | + android:color="#29ABE2"/> | ||
7 | + | ||
8 | + <size | ||
9 | + android:height="7dp" | ||
10 | + android:width="7dp"/> | ||
11 | + | ||
12 | +</shape> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -34,16 +34,6 @@ | ... | @@ -34,16 +34,6 @@ |
34 | android:src="@drawable/toolbar_logo" /> | 34 | android:src="@drawable/toolbar_logo" /> |
35 | </androidx.appcompat.widget.Toolbar> | 35 | </androidx.appcompat.widget.Toolbar> |
36 | 36 | ||
37 | - <androidx.viewpager.widget.ViewPager | ||
38 | - android:id="@+id/welcomeViewPager" | ||
39 | - android:layout_width="match_parent" | ||
40 | - android:layout_height="wrap_content" | ||
41 | - android:layout_gravity="top" | ||
42 | - android:layout_weight="1" | ||
43 | - android:elevation="-7dp"> | ||
44 | - | ||
45 | - </androidx.viewpager.widget.ViewPager> | ||
46 | - | ||
47 | <LinearLayout | 37 | <LinearLayout |
48 | android:layout_width="match_parent" | 38 | android:layout_width="match_parent" |
49 | android:layout_height="match_parent" | 39 | android:layout_height="match_parent" |
... | @@ -61,6 +51,30 @@ | ... | @@ -61,6 +51,30 @@ |
61 | 51 | ||
62 | </LinearLayout> | 52 | </LinearLayout> |
63 | 53 | ||
54 | + <FrameLayout | ||
55 | + android:layout_width="match_parent" | ||
56 | + android:layout_height="wrap_content"> | ||
57 | + | ||
58 | + <androidx.viewpager.widget.ViewPager | ||
59 | + android:id="@+id/welcomeViewPager" | ||
60 | + android:layout_width="match_parent" | ||
61 | + android:layout_height="262dp" | ||
62 | + android:layout_gravity="top" | ||
63 | + android:layout_weight="1"> | ||
64 | + | ||
65 | + </androidx.viewpager.widget.ViewPager> | ||
66 | + | ||
67 | + <com.example.vip.CircleIndicator | ||
68 | + android:id="@+id/ciMainActivity" | ||
69 | + android:layout_width="wrap_content" | ||
70 | + android:layout_height="wrap_content" | ||
71 | + android:layout_gravity="bottom|center_horizontal" | ||
72 | + android:layout_marginBottom="20dp" | ||
73 | + app:layout_constraintBottom_toBottomOf="parent" | ||
74 | + app:layout_constraintEnd_toEndOf="parent" | ||
75 | + app:layout_constraintStart_toStartOf="parent" /> | ||
76 | + </FrameLayout> | ||
77 | + | ||
64 | <LinearLayout | 78 | <LinearLayout |
65 | android:layout_width="match_parent" | 79 | android:layout_width="match_parent" |
66 | android:layout_height="wrap_content" | 80 | android:layout_height="wrap_content" | ... | ... |
-
Please register or login to post a comment