Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- VirtualBox
- 조동화 은퇴식
- textview
- 우삼겹 쌀국수
- setStyle
- diskCacheStrategy
- 이마트프랜들리존
- 게스트 확장
- 조동화선수
- CentOS 7
- 정보처리기사
- 행복라이브존
- 인천 맛집
- Linux
- divider
- 리눅스
- Android
- RecyclerView
- 인천SK와이번스
- 안드로이드
- 문학야구장
- 인천 논현동
- 땀땀
- 버추얼박스
- SK와이번스
- skipMemoryCache
- KIA타이거즈
- 인천SK행복드림구장
- Java
- 1루 응원지정석
Archives
- Today
- Total
쭌2 블로그
[안드로이드/Android] Button의 기본 Padding 제거하기 본문
안드로이드 Button에는 기본으로 Padding이 잡혀있습니다.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
그래서 Button에 따로 layout_width, layout_height 속성을 정해주지 않으면,
이렇게 기본 Padding이 적용되어 크기가 잡히는데요.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/blue_dark" />
<stroke android:width="0dp" android:color="@color/blue_dark" />
<padding android:bottom="@dimen/padding_8"
android:left="@dimen/padding_23"
android:right="@dimen/padding_23"
android:top="@dimen/padding_8" />
<corners android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
</item>
<item android:state_pressed="false">
<shape>
<solid android:color="@color/blue_dark" />
<stroke android:width="0dp" android:color="@color/blue_dark" />
<padding android:bottom="@dimen/padding_8"
android:left="@dimen/padding_23"
android:right="@dimen/padding_23"
android:top="@dimen/padding_8" />
<corners android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
</item>
</selector>
이럴경우 위와 같이 Button Selector를 만들어 Padding 값을 설정해주고 Button에 background를 먹여도 기본 Button의 Padding이 제거되지 않아 Selector의 Padding이 적용되지 않습니다.
이때는 아래와 같이 Button에 minWidth, minHeight 속성을 0dp로 설정해주면 간단하게 Button의 기본 Padding을 제거할 수 있습니다.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_blue_dark_onoff"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="Button" />
Button의 기본 Padding이 제거되고 위의 Selector에서 설정한 Padding이 적용된 것이 보이시죠? 이처럼 Button의 minWidth, minHeight 속성을 이용하면 간단하게 Button의 Padding 값을 제거할 수 있습니다.
'IT > Android' 카테고리의 다른 글
[안드로이드/Android] Glide 라이브러리 이미지 캐시를 이용하지 않고 로딩하기 (0) | 2019.06.13 |
---|---|
[안드로이드/Android] ViewPager Swiping 제어하기 (0) | 2018.09.12 |
[안드로이드/Android] Java 코드에서 TextView setStyle 적용하기 (0) | 2018.09.06 |
[안드로이드/Android] dp 단위를 px 단위로 변환하는 2가지 방법 (0) | 2018.08.22 |
[안드로이드/Android] RecyclerView 사용하기(3) - Add left and right margin to dividers (0) | 2018.08.18 |
Comments