나의 플랫폼/안드로이드
[Android] Percent Layout
GsBOB
2015. 12. 1. 10:38
안드로이드 최신 블로그 글을 읽다가 괜찮은 Layout이 있어 공유하고자 한다.
https://plus.google.com/+AndroidDevelopers/posts/C8oaLunpEEj
바로 PercentFrameLayout 와 PercentRelativeLayout 이다.
이름에서 느껴지지만! 바로 Percent로써 레이아웃을 잡을 수 있다.
<android.support.percent.PercentFrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"
android:text="test"/>
</android.support.percent.PercentFrameLayout>
결과 화면
이제 dp 값으로 걱정할 필요 없이 이 API를 이용하면 좋을 듯 하다~
참고로 이 API를 보니 API16 버전에서도 잘 돌아간다
중요한점!!
PercentLayout안에 바로 하위 뷰만 적용 되지 그 아래 뷰에 대해서는 적용이 되지 않습니다.
예를 들어 PercentFrameLayout > LinearLayout > ImageView에서 ImageView에 Percent를 줘봤자 적용 되지 않고 LinearLayout만 적용이 됩니다.
참고하세요.