woong's

Android PercentLayout 사용하기 본문

Develop/Android

Android PercentLayout 사용하기

dlsdnd345 2016. 2. 14. 18:41
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android PercentLayout 사용하기


http://www.kmshack.kr/android-percentlayout/#comment-1875


위 김민수님 블로그를 참고 하였습니다.


안녕하세요. 몇일전에 Android 6.0 마시멜로우 버전이 공개 되었습니다.

마시멜로우가 공개 되면서 여러가지 기능이 추가 된것 같습니다 .


- Customtabs

- Percent

- Recommendation,

- preference-v7

preference-v14


등이 공개 되었다고 합니다.


1. percentLayout 소개


percent 라이브러리에 대해서 사용해보고 블로그를 적어 보려 합니다.

percentLayout 은 기존의 weight 와 비슷한 개념인것 같습니다.
 

percentLayout

- percentFrameLayout

- percentRelativeLayout
 

같은점

- 비율을 통해서 레이아웃의 크기 등을 지정 할수 있다.


차이점

- weight 는 LinearLayout / percent 는 RelativeLayout


속성

- heightPercent

- widthPercent

- marginBottomPercent

- marginEndPercent

- marginLeftPercent

- marginRightPercent

- marginStartPercent

- marginTopPercent


3. percentLayout 준비


build.gradle 라이브러리 추가


1
   compile 'com.android.support:percent:23.0.0'

cs

 




4. percentLayout 사용방법



의 속성을 사용해서 레이아웃을 작성해보면 될 것 같습니다.

weight 를 써보신분이면 쉽게 사용해보면서 익힐수 있을것 같습니다.




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

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

 

    <android.support.percent.PercentRelativeLayout

        android:layout_width="0dp"

        android:layout_height="0dp"

        android:background="#ff0000"

        android:layout_centerInParent="true"

        app:layout_heightPercent="80%"

        app:layout_widthPercent="80%">

 

        <android.support.percent.PercentRelativeLayout

            android:layout_width="0dp"

            android:layout_height="0dp"

            android:background="#ffff00"

            app:layout_heightPercent="40%"

            app:layout_marginLeftPercent="10%"

            app:layout_marginTopPercent="10%"

            android:layout_alignParentLeft="true"

            android:layout_alignParentTop="true"

            app:layout_widthPercent="40%"/>

 

        <android.support.percent.PercentRelativeLayout

            android:layout_width="0dp"

            android:layout_height="0dp"

            android:background="#ffffff"

            app:layout_heightPercent="40%"

            app:layout_marginPercent="10%"

            android:layout_alignParentRight="true"

            android:layout_alignParentTop="true"

            app:layout_widthPercent="40%"/>

 

        <android.support.percent.PercentRelativeLayout

            android:layout_width="0dp"

            android:layout_height="0dp"

            android:background="#00ff00"

            app:layout_heightPercent="40%"

            app:layout_marginLeftPercent="10%"

            app:layout_marginBottomPercent="10%"

            android:layout_alignParentLeft="true"

            android:layout_alignParentBottom="true"

            app:layout_widthPercent="40%"/>

 

        <android.support.percent.PercentRelativeLayout

            android:layout_width="0dp"

            android:layout_height="0dp"

            android:background="#0000ff"

            app:layout_heightPercent="40%"

            app:layout_marginRightPercent="10%"

            app:layout_marginBottomPercent="10%"

            android:layout_alignParentRight="true"

            android:layout_alignParentBottom="true"

            app:layout_widthPercent="40%"/>

 

 

    </android.support.percent.PercentRelativeLayout>

 

 

</android.support.percent.PercentRelativeLayout>

 

cs




Comments