๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ปTech/๐ŸŒตandroid

[์•ˆ๋“œ๋กœ์ด๋“œ] ์›ํ˜• ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ์‚ฌ์šฉ๋ฒ• ๋ฐ ๊ทธ๋ผ๋ฐ์ด์…˜ ์ ์šฉ

by _viper_ 2015. 9. 14.
๋ฐ˜์‘ํ˜•

์›ํ˜• ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ์‚ฌ์šฉ๋ฒ•๊ณผ ๊ทธ๋ผ๋ฐ์ด์…˜ ํšจ๊ณผ ์ ์šฉ ๋ฐ ์ปฌ๋Ÿฌ ๋ณ€๊ฒฝ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
์ œ๊ฐ€ ์‚ฌ์šฉํ•œ ๋ฐฉ๋ฒ•์€ ์›ํ˜• ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ”๋ฅผ RelativeLayout์œผ๋กœ ๋‘ ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ”๋ฅผ ๊ฒน์ณ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.
์šฐ์„  res -> drawable์— 2๊ฐ€์ง€ xml์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

<circular_progress_background.xml>

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/progress">
        <rotate
            android:fromDegrees="270"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="270" >
            <shape
                android:innerRadius="64dp"
                android:useLevel="true"
                android:shape="ring"
                android:thickness="10dp" >
                <gradient
                    android:centerColor="@color/color_ffffff"
                    android:endColor="@color/color_ffffff"
                    android:startColor="@color/color_ffffff"
                    android:type="sweep" />
            </shape>
        </rotate>
    </item>

</layer-list>

<circular_progress_foreground.xml>

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/progress">
        <rotate
            android:fromDegrees="270"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="270" >
            <shape
                android:innerRadius="64dp"
                android:useLevel="true"
                android:shape="ring"
                android:thickness="10dp" >
                <gradient
                    android:startColor="@color/color_edf436"
                    android:endColor="@color/color_3aedf4"
                    android:type="sweep" />
            </shape>
        </rotate>
    </item>

</layer-list>

android:startColor, android:endColor, android:centerColo๋กœ ๊ทธ๋ผ๋ฐ์ด์…˜ ํšจ๊ณผ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
๊ทธ ๋‹ค์Œ res -> layout ํด๋”์— xml ํŒŒ์ผ ํ•˜๋‚˜๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

<activityCircularProgressbar.xml>

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp" >

            <ProgressBar
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="148dp"
                android:layout_height="148dp"
                android:layout_centerInParent="true"
                android:indeterminate="false"
                android:progress="100"
                android:progressDrawable="@drawable/circular_progress_background" />

            <ProgressBar
                android:id="@+id/cpb"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="148dp"
                android:layout_height="148dp"
                android:layout_centerInParent="true"
                android:indeterminate="false"
                android:progressDrawable="@drawable/circular_progress_foreground" />
</RelativeLayout>

 

[๊ฒฐ๊ณผ ํ™”๋ฉด]