์ฝ์งํ๋ฉด์ ๊ฒฐ๊ตญ์ ์ํ๋ UI๋ฅผ ๋ง๋ค์๋ค. ์ฝ์งํ๋ฉฐ ์๊ฒ๋ ๊ฒ๋ค์ ๊ธฐ๋กํ๋ค.
์ํ๋ ๋ชจ์ต
1. ํญ๋ค ๋ฐ๋ฅ์๋ ๋ผ์ธ์ด ๊น๋ ค์๋ค.
2. ์ธ๋์ผ์ดํฐ ๊ธธ์ด๊ฐ ํญ ํ๋์ ๋์ด๋ณด๋ค๋ ์ข์ง๋ง ํ ์คํธ ๋๋น๋ณด๋ค๋ ํฌ๋ค
3. ํญ ๊ฐ ๋๋ฐ์ด๋๊ฐ ์๋ค.
๊ฒฐ๊ณผ ์ฝ๋
<com.google.android.material.tabs.TabLayout
android:id="@+id/target"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@drawable/bg_tablayout"
app:tabIndicator="@drawable/indicator_2">
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="๋ธ๊ธฐ" />
<com.google.android.material.tabs.TabItem
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="์ฌ๊ณผ" />
</com.google.android.material.tabs.TabLayout>
์์ธ : https://ovso.github.io/blog/2018/11/06/tablayout_divider/
TabLayout์ ๊ตฌ๋ถ์ (Divider) ๋ฃ๊ธฐ
TabLayout์ ๊ตฌ๋ถ์ ๋ฃ๊ธฐ
ovso.github.io
์ฌ์ฉ๋ drawable ํ์ผ๋ค
1) ํฐ ๋ฐฐ๊ฒฝ์ ๋ฐ๋ฅ ์ค
ํฐ ๋ฐฐ๊ฒฝ์ ๋ฐ๋ฅ ์ค ๊ทธ๋ฆฌ๋ ๋ฐฉ์์ผ๋ก, ํฐ ๋ฐฐ๊ฒฝ์ ํ ๋๋ฆฌ ์์ ๋ฃ์ ์ฌ๊ฐํ shape์ ์์ ์ ๋ง์ง ๊ฐ์ ๋ง์ด๋์ค ๊ฐ์ ์ฃผ๋ ๋ฐฉ์๋ ์๋ค. ์ ๋ง ์ด๋ ๊ฒ ๋ฐ์ ๊ทธ๋ฆฌ์ง ๋ชปํ๋๊ฐ... ๊ตฌ๊ธ๋งํด๋ ๋ฑํ ๋ ์ข์ ๋ฐฉ๋ฒ๋ค์ ๋ชป ์ฐพ๊ฒ ๋ค.
2) ์ธ๋์ผ์ดํฐ
์์ธ : https://sweetcoding.tistory.com/162
Android tab bottom indicator change shape (์๋๋ก์ด๋ Tab Indicator ๋ชจ์ ๋ณ๊ฒฝ ํ๊ธฐ)
์ฐ๋ฆฌ๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉ ํ๋ Tab Layout ์ ์ ์ฉ ํ๋ฉด ์ด๋ฐ ๋ชจ์ต๋๋ค. ํ๋จ์ Indicator ๋ชจ์์ ์๋์ ๊ฐ์ด ๋ณ๊ฒฝ ํ๊ณ ์ถ์ผ๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ ๊น? ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ๋ค. 1. tab_selector.xml ์ drawable ํด๋์
sweetcoding.tistory.com
์์ธ์ด ์จ์ฃผ์ ํ์(๊ณ์ธต๊ตฌ์กฐ)๋๋ก ์ธ๋์ผ์ดํฐ๋ฅผ ๋ง๋ค์ด์ผ ํ๋ค. ๊ทธ๋ฌ์ง ์์์ ์ฝ์งํด์จ ๊ฑฐ์๋ค.
3) ๋๋ฐ์ด๋
๋๋ฐ์ด๋๋ฅผ ๊ทธ๋ฆฌ๋๋ฐ ๊ตฌ์ง custom drawable์ ์์ฑํ์ง ์์๋ ๋๋ค๋ ๊ฒ์ ํ์ธํ๋ค. ์์ ๋๋ฐ์ด๋ ์ฝ์ ์ฝ๋ ์ด๋ฏธ์ง์์ ์ฃผ์์ฒ๋ฆฌ๋ ๋ถ๋ถ์ผ๋ก ๋๋ฐ์ด๋์ width ๋ถ๋ถ ์ฌ์ด์ฆ ์กฐ์ ๊ฐ๋ฅํ๋ค. ๋๋ drawable์์ width ์ฌ์ด์ฆ๋ฅผ ์ก์ผ๋ ์ฝ๋ ์ ๋ฐ๋ก ๋๋ฐ์ด๋์ width๋ฅผ ์กฐ์ ํ ํ์๊ฐ ์์๋ค.
์ฝ์ง๋ก ์๊ฒ๋ ๊ฒ๋ค
TabLayout ์์ฑ app:tabIndicatorFullWidth="false"
tabIndicatorFullWidth ์์ฑ์ผ๋ก ์ธ๋์ผ์ดํฐ์ ๋๋น๋ฅผ ์กฐ์ ํ ์ ์๋ค.
true > ํญ ๋๋น ๊ฝ ์ฑ์
false > ํญ์ text ๋๋น ๋งํผ ์ฑ์
TabItem ์์ฑ android:layout + TabLayout ์์ฑ app:tabIndicatorHeight
TabItem ์ ์์ฑ์ layout xml ํ์ผ ๋ ํผ๋ฐ์ค๋ฅผ ๋ฃ์ด TabItem์ ๋ ์ด์์์ ์ปค์คํ ํ ์ ์๋ค.
TabLayout์ ์์ฑ์ผ๋ก ์ธ๋์ผ์ดํฐ์ ๋์ด๋ฅผ ์กฐ์ ํ ์ ์๋ค.
๋๋ ์ด ์์ ์์ ์ธ๋์ผ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ ๋์ ์, ์ปค์คํ ๋ ์ด์์์ ํ๋จ์ ๊ณ ์ ๋ทฐ๋ฅผ ๋ง๋ค๊ณ , select ์ํ ์ฌ๋ถ์ ๋ฐ๋ผ ์ปค์คํ ๋ ์ด์์์ ํ๋จ ๋ทฐ๊ฐ ๋ ธ์ถ๋๊ฑฐ๋ ๋ ธ์ถ๋์ง ์๋๋ก ํ๋ค.
TabItem์ ์ปค์คํ ๋ ์ด์์์์ TextView์ ์์ด๋๋ฅผ "@android:id/text1"๋ผ๊ณ ์จ์ผ์ง TabItem์ android:text ์์ฑ์ ๋ฃ์ ๊ฐ์ด ์ ์์ ์ผ๋ก ์ปค์คํ ๋ ์ด์์์์ ๋์จ๋ค. ์ค์.
์์ธ : https://stackoverflow.com/a/38035415/9287140
How is TabItem used when placed in the layout XML?
The TabLayout documentation gives an example of nesting TabItem directly inside TabLayout like so:
stackoverflow.com
ํ๋จ ๋ทฐ์ background๋ selector drawable๋ก ๋ถ๋ชจ์ ์์ฑ์ android:duplicateParentState="true"๋ก ๋ฐ์์ ๋์ํ๊ฒ ํ๋ค.
'๋น ๊ตฌ๋ฉ ์ฑ์ฐ๊ธฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android] LocalDate, LocalTime, LocaleDateTime ์ฐ๊ณ ์ถ์๋ฐ Android API version์ ๊ฑธ๋ ค์ (0) | 2021.09.28 |
---|---|
[Android]DownloadManager (0) | 2021.09.23 |
[Android] ๋ ์ด์์ ์ ๋ฐ์ดํธ ์๋ ์ ๋๋ฉ์ด์ ์ฒ๋ฆฌ (0) | 2021.09.02 |
[Android] ๋ฆฌ์ฌ์ดํด๋ฌ๋ทฐ notifyDataSetChanged() ์ ๋๋ฉ์ด์ ๋์ ์ ํ ๋ (0) | 2021.09.02 |
[Android] ExoPlayer ๋์์ ํ๋ ์ด (0) | 2021.09.01 |