위 포스팅에서 소개한것과 같이, 로또번호 추첨기에서 썼던 것을 기반으로하여 drawble에대해서 정리해보려고한다.
# ShapeDrawable
drawalbe에는 많은 종류가 있지만 해당 프로젝트를 하면서 shape를 이용해 원형모형의 색있는공을 만들었다.
저 코드를 그대로 해석해보면 이런 파란색 원이 나온다. 그리고 색상을 수정하여 아래와 같이 배경이미지를 만들고, background속성으로 주면 적용 된다.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<solid android:color="#0E5DE4"/>
<size
android:height="44dp"
android:width="44dp"/>
</shape>
모든 만약 공별로 img파일(png)을 배경으로 주면 리소스면에서 꽤 손해를 보게 된다. 저렇게 xml로 표현 가능한 경우에는 저런식으로 작성하게되면 용량면에서 이득을 볼 수 있다고 한다.
공식문서 예제.
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient
android:angle="integer"
android:centerX="float"
android:centerY="float"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer" />
<size
android:width="integer"
android:height="integer" />
<solid
android:color="color" />
<stroke
android:width="integer"
android:color="color"
android:dashWidth="integer"
android:dashGap="integer" />
</shape>
태그에 따른 꽤 많은 속성들이 존재하기 때문에 내가 필요할때마다 공식문서를 참고해가며 만들어 보도록 해야겠다.
공식문서참고.