NestedScrollView๋ฅผ ์ฌ์ฉํ ๋ ์ฃผ๋ก ๋ด๋ถ์ RecyclerView๋ฅผ ๋ง์ด ์ฌ์ฉํฉ๋๋ค. ์ด๋ ๋ฐ์ํ๋ ๋ฌธ์ ๊ฐ focus๊ฐ RecyclerView๋ก ๊ฐ์ ์๋จ์ ๋ด์ฉ์ด ๋ ์์์๋ ๋ถ๊ตฌํ๊ณ RecyclerView๊ฐ ์๋ ์์น๋ก Scroll์ด ๋๋ ๊ฒ ์ ๋๋ค.
์ด๋ฐ ํ์์ด ๋ํ๋๋ ์ด์ ๋ ScrollView๊ฐ ์์๋ ์์์ RecyclerView์ ๊ฐ์ด Scroll์ด ๊ฐ๋ฅํ ๋ทฐ๊ฐ ์์ผ๋ฉด, ํด๋น ์์ ๋ทฐ์๊ฒ focus๊ฐ ๋บ๊ธฐ๊ธฐ ๋๋ฌธ์ ๋๋ค. ๊ทธ๋ ๊ธฐ์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ ์์๋ทฐ์๊ฒ focus๊ฐ ๊ฐ์ง ์๋๋ก ๋ง๋ค์ด์ผ ํฉ๋๋ค. ์ฌ๊ธฐ์ ๊ฐ์ฅ ๋จผ์ ๋๋ ์๊ฐ์ android:focusable(Focus ๊ฐ๋ฅ ์ฌ๋ถ), android:focusableInTouchMode (์ฌ์ฉ์ ํฐ์น์ ์ธํ Focus ๊ฐ๋ฅ์ฌ๋ถ) ์ด๊ฒ ์ง๋ง ์ด ๋์ ์ ํ ํจ๊ณผ๊ฐ ์์ต๋๋ค. ์คํ๋ ค ์ด ๋์ ์ ์ธํ์์๋ ๋ค๋ฅธ ๋ฌธ์ ๊ฐ ์ผ๊ธฐ๋ ํ๋ฅ ์ด ๋์ต๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ์๊ฐ๋ณด๋ค ๊ฐ๋จํฉ๋๋ค. ๋ฑ ํ ์ค์ด๋ฉด ์ถฉ๋ถํ๋ฐ์ ๋ฐ๋ก ๋ค์ ์ฝ๋์ ๋๋ค.
android:descendantFocusability="blocksDescendants"
Android Developer descendantFocusablility ๋งํฌ
ViewGroup | Android ๊ฐ๋ฐ์ | Android Developers
developer.android.com
์ด ์์ฑ์ ViewGroup๊ณผ ๊ทธ์ ํ์๋ View๊ฐ์ Focus๋ฅผ ๊ฐ์ ธ๊ฐ๋ ๊ด๊ณ๋ฅผ ์ ์ํ๋ ์์ฑ์ ๋๋ค. ์ฝ๊ฒ ๋งํ๋ฉด ๋ถ๋ชจ๊ฐ focus๋ฅผ ๊ฐ์ ธ๊ฐ์ง ์์์ด focus๋ฅผ ๊ฐ์ ธ๊ฐ์ง ์ ํ๋ ์์ฑ์ ๋๋ค. ํด๋น ์์ฑ์๋ 3๊ฐ์ง์ ๊ฐ์ ์ค์ ํ ์ ์๋๋ฐ์.
- afterDescendants
- ์์๋ค์ด focus๋ฅผ ์ฌ์ฉํ์ง ์์ ๊ฒฝ์ฐ๋ง focus๋ฅผ ๊ฐ์ง๋ค. (์์์๊ฒ ๋จผ์ ์ค๋ค.)
- beforeDescendants
- ์์๋ค๋ณด๋ค ๋จผ์ focus๋ฅผ ๋ฐ๋๋ค.
- blockDescendants
- ์์์ด focus๋ฅผ ๋ฐ์ง ๋ชปํ๊ฒ ํ๋ค.
์ฐ๋ฆฌ๊ฐ ์ค์ ํ ์์ฑ์ 3๋ฒ blockDescendants ์ ๋๋ค. ์์์ด ํฌ์ปค์ค๋ฅผ ๋ฐ์ ์ ์๊ฒ ํ๋ ๊ฒ ์ด์ฃ . ์ด์ ๋จ์ ๋ฌธ์ ๋ ์ด ์์ฑ์ ์ด๋์ ๋ฐฐ์นํ ์ง ์ ๋๋ค. NestedScrollView์ ์ง์ ์ด ์์ฑ์ ๋ฃ์ผ๋ฉด ์์์ด ๋๋ฌด ๋ง๊ธฐ ๋๋ฌธ์ ์ ์๋ํ์ง ์์ ๊ฒ ์ ๋๋ค. ๋ฐ๋ผ์ ์ด ์์ฑ์ ๋ฃ์๋์๋ RecyclerView๋ฅผ ๊ฐ์ธ๊ณ ์๋ ๋ถ๋ชจ์๊ฒ ์ ์ธํด์ผ ๋ฉ๋๋ค. ์๋์ ์ฝ๋๋ฅผ ๋ณด๋ฉด ์ดํด๊ฐ ์ฌ์ธ ๊ฒ ์ ๋๋ค.
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
//RecyclerView ๋ฐ๋ก ์์ ๋ถ๋ชจ์ ์ ์ธ
android:descendantFocusability="blocksDescendants">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
์ด๋ ๊ฒ ์ ์ธ์ ํด์ฃผ์๋ฉด RecyclerView ๊ฐ NestedScrollView์ focus๋ฅผ ๊ฐ์ ธ๊ฐ๋ ์ผ์ด ์์ ๊ฒ ์ ๋๋ค.
์ฆ๊ฑฐ์ด ์ฝ๋ฉํ์ธ์ :)
๊ฐ์ฌํฉ๋๋ค.
'Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Android Firebase ๋์ ๋งํฌ (Dynamic Link) (0) | 2020.07.24 |
---|---|
Firebase Release ๋ฒ์ SHA1 (0) | 2020.07.24 |
Android / EditText TouchMode Cursor ๊น๋นก์ ๋ฌธ์ ํด๊ฒฐ (0) | 2020.07.24 |