{"id":1035,"date":"2019-02-10T18:14:04","date_gmt":"2019-02-10T09:14:04","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=1035"},"modified":"2019-02-10T18:14:04","modified_gmt":"2019-02-10T09:14:04","slug":"android-custom-view%ec%bb%a4%ec%8a%a4%ed%85%80-%eb%b7%b0-%eb%a7%8c%eb%93%a4%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=1035","title":{"rendered":"Android Custom View(\ucee4\uc2a4\ud140 \ubdf0) \ub9cc\ub4e4\uae30"},"content":{"rendered":"<h1>\ucee4\uc2a4\ud140 \ubdf0 \ub9cc\ub4e4\uae30<\/h1>\n<h2>\ucee4\uc2a4\ud140\ubdf0\ub294 \uc65c \ud544\uc694\ud560\uae4c?<\/h2>\n<p>\uc548\ub4dc\ub85c\uc774\ub4dc \ud504\ub808\uc784\uc6cc\ud06c\uc5d0\uc11c \uae30\ubcf8 \uc81c\uacf5\ub418\ub294 \uc704\uc82f\ub4e4\ub85c\ub294 Button, TextView, EditText, ListView, CheckBox, RadioButton, Spinner \ub4f1\uc774 \uc788\uace0 \ub808\uc774\uc544\uc6c3\uc73c\ub85c\ub294 LinearLayout, FrameLayout, RelativeLayout \ub4f1\uc774 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ud558\uc9c0\ub9cc \uc2e4\uc81c\ub85c \uc571\uc744 \ub9cc\ub4e4\ub2e4 \ubcf4\uba74 \uae30\ud68d\uc790, \ub514\uc790\uc774\ub108, \uc0ac\uc6a9\uc790(\ud074\ub77c\uc774\uc5b8\ud2b8)\uc758 \uc694\uad6c\uc0ac\ud56d\uc5d0 \ub9de\ub294 \uae30\ub2a5\uc744 \uc704\uc758 \uc5f4\uac70\ud55c \ubdf0\ub4e4\ub85c \ub9cc\ub4e4\uae30 \uc5b4\ub835\uac70\ub098 \ubd88\uac00\ub2a5\ud55c \uacbd\uc6b0\uac00 \ubd80\uc9c0\uae30\uc218\uc785\ub2c8\ub2e4.\u00a0<\/p>\n<p>\uc608\ub97c\ub4e4\uba74, \uc6d0\ud615 \uc378\ub124\uc77c\uc744 \ud45c\ud604\ud558\uae30 \uc704\ud55c \ubdf0\ub97c \ub9cc\ub4e4\uae30 \uc704\ud574\uc11c ImageView\ub97c \uc0c1\uc18d\ud560 \uc218\uc788\uace0, \ud14d\uc2a4\ud2b8\uc758 \uc77c\ubd80 \ub0b4\uc6a9\ub9cc \ubcf4\uc5ec\uc8fc\uace0 \uc6d0\ud560 \ub54c \ud3bc\uccd0 \ubaa8\ub4e0 \ub0b4\uc6a9\uc744 \ubcf4\uc5ec\uc904 \uc218 \uc788\ub294 \ubdf0\ub97c \ub9cc\ub4e4\uae30 \uc704\ud574\uc11c\ub294 TextView\ub97c \uc0c1\uc18d\ud560 \uc218\ub3c4 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uc774\ub7f4\ub54c\ub294 \uc694\uad6c\uc0ac\ud56d\uc5d0 \ub9de\ub294 View\ub97c \uc9c1\uc811 \ub9cc\ub4dc\ub294 \ubc29\ubc95\ubc16\uc5d0 \uc5c6\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>\ucee4\uc2a4\ud140\ubdf0 \ub9cc\ub4dc\ub294 \uae30\ubcf8\uc801\uc778 \uc6d0\ub9ac<\/h2>\n<ol>\n<li>\uae30\uc874\uc5d0 \uc874\uc7ac\ud558\ub294 View \ud074\ub798\uc2a4\ub97c \uc0c1\uc18d\ud569\ub2c8\ub2e4.<\/li>\n<li>onDraw(), onMeasure(), onKeyDown()\uacfc \uac19\uc774 \uc2dc\uc791\ud558\ub294 \ud0a4\uc6cc\ub4dc\uac00 &#8216;on&#8217;\uc778 \uc218\ud37c \ud074\ub798\uc2a4 \uba54\uc11c\ub4dc\ub97c \uc624\ubc84\ub77c\uc774\ub4dc \ud569\ub2c8\ub2e4.<\/li>\n<li>\uc0c8\ub85c\ub9cc\ub4e0 \ucee4\uc2a4\ud140 \ubdf0\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4. \uae30\uc874\uc5d0 \uc0ac\uc6a9\ud558\ub358 \ubc29\uc2dd\uacfc \uac19\uc774 xml\ub808\uc774\uc544\uc6c3 \ub4f1\uc5d0 \uc0ac\uc6a9\ud569\ub2c8\ub2e4<\/li>\n<\/ol>\n<h2>onDraw()\uc640\u00a0 onMeasure()<\/h2>\n<p>onDraw() \uc5d0\uc11c\ub294 \uac1c\ubc1c\uc790\uac00 \uc6d0\ud558\ub294\ub300\ub85c \uad6c\ud604\ud560 \uc218 \uc788\ub294 Canvas\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. onDraw()\ub97c \uc624\ubc84\ub77c\uc774\ub4dc \ud558\uace0,\u00a0 Canvas\ub97c \uc774\uc6a9\ud558\uc5ec \uadf8\ub9ac\uace0 \uc2f6\uc740 \ub0b4\uc6a9\uc744 \ud654\uba74\uc5d0 \uadf8\ub9ac\uba74 \ub429\ub2c8\ub2e4.<\/p>\n<p><em>Note: 3D \uadf8\ub798\ud53d\uc5d0\ub294 \uc801\uc6a9\ub418\uc9c0 \uc54a\uc73c\uba70 View\ub300\uc2e0 SurfaceView\ub97c \uc0c1\uc18d\ud558\uc5ec \ubcc4\ub3c4\uc758 \uc4f0\ub808\ub4dc\uc5d0\uc11c \uadf8\ub824\uc57c\ud569\ub2c8\ub2e4. <a href=\"https:\/\/www.charlezz.com\/?p=742\">OpenGL ES<\/a>\uad00\ub828 \ud3ec\uc2a4\ud305\uc744 \ucc38\uace0\ud574\uc8fc\uc138\uc694<\/em><\/p>\n<p>onMeasure()\ub294 \uc870\uae08 \ub354 \ubcf5\uc7a1\ud55c\ub370\uc694 , \ubdf0\uc640 \ubdf0\uc5d0 \ud3ec\ud568\ub41c \ucee8\ud150\uce20\ub97c \uce21\uc815\ud558\uc5ec\uc11c \uce21\uc815\ub41c width\uc640 height\ub97c \uacb0\uc815\ud569\ub2c8\ub2e4. onMeasure()\ub294 measure(int,int)\uc5d0 \uc758\ud574 \ud638\ucd9c\uc774 \ub429\ub2c8\ub2e4. measure \uba54\uc18c\ub4dc\uc5d0\uc11c\ub294 \ubdf0\uc758 \uc0ac\uc774\uc988\ub97c \uce21\uc815\ud558\uace0 \uc2e4\uc81c \uce21\uc815\ub41c \uc0ac\uc774\uc988\uac00 \uc218\ud589\ub418\ub294 \uacf3\uc740 onMeasure()\uc785\ub2c8\ub2e4.\u00a0<\/p>\n<p>onMeasure()\ub97c \uc624\ubc84\ub77c\uc774\ub4dc \ud558\ub294 \uacbd\uc6b0 setMeasuredDimension(int, int)\ub97c \ud638\ucd9c\ud574\uc11c \uce21\uc815\ub41c \uc0ac\uc774\uc988\ub97c \uc800\uc7a5\ud560 \uc218 \uc788\ub3c4\ub85d \ud574\uc57c \ud569\ub2c8\ub2e4. super.onMeasure()\ub97c \ud638\ucd9c \ud558\ub294\uac8c \ubc29\ubc95\uc774 \ub420\uc218 \uc788\uc2b5\ub2c8\ub2e4.(onMeasure\ub0b4\uc5d0\uc11c \uc774\ubbf8 \ud55c\ubc88 \ud638\ucd9c \ud558\uace0 \uc788\uae30 \ub54c\ubb38\uc5d0..)<\/p>\n<h2>\ud504\ub808\uc784\uc6cc\ud06c\uac00 \ud638\ucd9c\ud558\ub294 \ub2e4\ub978 View \uba54\uc18c\ub4dc<\/h2>\n<div class=\"devsite-table-wrapper\">\n<table border=\"2\" width=\"85%\" align=\"center\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>\ud56d\ubaa9<\/th>\n<th>\uba54\uc18c\ub4dc<\/th>\n<th>\uc124\uba85<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td rowspan=\"2\">\uc0dd\uc131<\/td>\n<td>\uc0dd\uc131\uc790<\/td>\n<td>\ubdf0\uac00 \ub7f0\ud0c0\uc784\uc5d0 \ucf54\ub4dc\ub85c \ubd80\ud130 \uc0dd\uc131\ub418\ub294 \uacbd\uc6b0\uc640, xml \ud30c\uc77c\uc744 \ud30c\uc2f1\ud558\ub294 \uacbd\uc6b0 \ub450\uac00\uc9c0\uac00 \uc788\uc2b5\ub2c8\ub2e4.<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onFinishInflate()\"><span>onFinishInflate()<\/span><\/a><\/code><\/td>\n<td>\ubdf0, \ub610\ub294 \ubdf0\uadf8\ub8f9\uc758 \uacbd\uc6b0 \uc790\uc2dd\ubdf0\ub4e4\uc774 \uc778\ud50c\ub808\uc774\uc158\uc774 \ub2e4 \ub05d\ub098\uba74 \ud638\ucd9c \ub429\ub2c8\ub2e4.<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"3\">\ub808\uc774\uc544\uc6c3<\/td>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onMeasure(int,%20int)\"><span>onMeasure(<wbr \/>int,<wbr \/>\u00a0int)<\/span><\/a><\/code><\/td>\n<td>\ubdf0, \uc790\uc2dd\ubdf0\uc758 \uc0ac\uc774\uc988\uac00 \uacb0\uc815\ub420\ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onLayout(boolean,%20int,%20int,%20int,%20int)\"><span>onLayout(<wbr \/>boolean,<wbr \/>\u00a0int,<wbr \/>int,<wbr \/>\u00a0int,<wbr \/>\u00a0int)<\/span><\/a><\/code><\/td>\n<td>\ubdf0, \uc790\uc2dd\ubdf0\uc758 \uc704\uce58\uac00 \uacb0\uc815\ub420\ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onSizeChanged(int,%20int,%20int,%20int)\"><span>onSizeChanged(<wbr \/>int,<wbr \/>\u00a0int,<wbr \/>int,<wbr \/>\u00a0int)<\/span><\/a><\/code><\/td>\n<td>\ubdf0\uc758 \uc0ac\uc774\uc988\uac00 \ubcc0\uacbd\ub418\uc5c8\uc744\ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td>\uadf8\ub9ac\uae30<\/td>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onDraw(android.graphics.Canvas)\"><span>onDraw(<wbr \/>Canvas)<\/span><\/a><\/code><\/td>\n<td>\ubdf0\uac00 \uac00\uc9c0\uace0 \uc788\ub294 \ucf58\ud150\uce20\ub97c \uadf8\ub9b4\ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"4\">\uc774\ubca4\ud2b8 \ucc98\ub9ac<\/td>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onKeyDown(int,%20android.view.KeyEvent)\"><span>onKeyDown(<wbr \/>int,<wbr \/>\u00a0KeyEvent)<\/span><\/a><\/code><\/td>\n<td>\ud0a4 \uc774\ubca4\ud2b8\uac00 \ub20c\ub838\uc744 \ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onKeyUp(int,%20android.view.KeyEvent)\"><span>onKeyUp(<wbr \/>int,<wbr \/>\u00a0KeyEvent)<\/span><\/a><\/code><\/td>\n<td>\ud0a4\uac00 \ub5a8\uc5b4\uc84c\uc744 \ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onTrackballEvent(android.view.MotionEvent)\"><span>onTrackballEvent(<wbr \/>MotionEvent)<\/span><\/a><\/code><\/td>\n<td>\ud2b8\ub799\ubcfc \uc774\ubca4\ud2b8 \ubc1c\uc0dd\uc2dc \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onTouchEvent(android.view.MotionEvent)\"><span>onTouchEvent(<wbr \/>MotionEvent)<\/span><\/a><\/code><\/td>\n<td>\uc2a4\ud06c\ub9b0\uc5d0 \ud130\uce58 \uc774\ubca4\ud2b8 \ubc1c\uc0dd\uc2dc \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"2\">\ud3ec\ucee4\uc2a4<\/td>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onFocusChanged(boolean,%20int,%20android.graphics.Rect)\"><span>onFocusChanged(<wbr \/>boolean,<wbr \/>int,<wbr \/>\u00a0Rect)<\/span><\/a><\/code><\/td>\n<td>\ud3ec\ucee4\uc2a4\ub97c \uc783\uc744 \ub54c \ud638\ucd9c\ub428\u00a0<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onWindowFocusChanged(boolean)\"><span>onWindowFocusChanged(<wbr \/>boolean)<\/span><\/a><\/code><\/td>\n<td>\uc708\ub3c4\uc6b0\uac00 \ud3ec\ud568\ud558\uace0 \uc788\ub294 \ubdf0\uac00 \ud3ec\ucee4\uc2a4\ub97c \uc5bb\uac70\ub098 \uc783\uc744\ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"3\">Attaching<\/td>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onAttachedToWindow()\"><span>onAttachedToWindow()<\/span><\/a><\/code><\/td>\n<td>\uc708\ub3c4\uc6b0\uc5d0 \ubdf0\uac00 \ubd99\uc744\ub54c \ud638\ucd9c\ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onDetachedFromWindow()\"><span>onDetachedFromWindow()<\/span><\/a><\/code><\/td>\n<td>\uc708\ub3c4\uc6b0\ub85c\ubd80\ud130 \ubdf0\uac00 \ub5a8\uc5b4\uc9c8 \ub54c \ud638\ucd9c \ub428<\/td>\n<\/tr>\n<tr>\n<td><code><a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html#onWindowVisibilityChanged(int)\"><span>onWindowVisibilityChanged(<wbr \/>int)<\/span><\/a><\/code><\/td>\n<td>\uc708\ub3c4\uc6b0\uac00 \uac00\uc9c0\uace0 \uc788\ub294 \ubdf0\uc758 \uac00\uc2dc\uc131\uc774 \ubcc0\uacbd \ub420 \ub54c \ud638\ucd9c \ub428<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\uc774\ubbf8 \uc874\uc7ac\ud558\ub294 View\ub97c \ucee4\uc2a4\ud140 \ud574\ubcf4\uc790(LinedEditText;\ubc11\uc904\uc788\ub294 EditText\ub9cc\ub4e4\uae30)<\/h2>\n<pre class=\"lang:java decode:true\">public class LinedEditText extends EditText {\r\n        private Rect mRect;\r\n        private Paint mPaint;\r\n        \/\/ \uc774 \uc0dd\uc131\uc790\ub294 LayoutInflter\uc5d0\uc11c \uc0ac\uc6a9\ub429\ub2c8\ub2e4.\r\n        public LinedEditText(Context context, AttributeSet attrs) {\r\n            super(context, attrs);\r\n            \/\/ Rect\uc640 Paint\uac1d\uccb4 \uc0dd\uc131\r\n            \/\/ Paint\uac1d\uccb4\uc5d0 \uc2a4\ud0c0\uc77c\uacfc \uc0c9\uc0c1 \uc785\ud798\r\n            mRect = new Rect();\r\n            mPaint = new Paint();\r\n            mPaint.setStyle(Paint.Style.STROKE);\r\n            mPaint.setColor(0x800000FF);\r\n        }\r\n\r\n        @Override\r\n        protected void onDraw(Canvas canvas) {\r\n            \/\/ View\uc548\uc758 \ud14d\uc2a4\ud2b8\uc758 \ub77c\uc778\uc218\uac00 \uba87\uac1c\uc778\uc9c0 \uac00\uc838\uc635\ub2c8\ub2e4.\r\n            int count = getLineCount();\r\n            Rect r = mRect;\r\n            Paint paint = mPaint;\r\n            \/*\r\n             * EditText\uc758 \ubaa8\ub4e0 \ub77c\uc778\uc5d0 \ubc11\uc904\uc744 \uadf8\ub9bd\ub2c8\ub2e4\r\n             *\/\r\n            for (int i = 0; i &lt; count; i++) {\r\n                \/\/ \ud604\uc7ac \ud14d\uc2a4\ud2b8 \ub77c\uc778\uc758 \ubca0\uc774\uc2a4\ub77c\uc778 \uc88c\ud45c\ub97c \uac00\uc838\uc635\ub2c8\ub2e4.\r\n                int baseline = getLineBounds(i, r);\r\n                \/*\r\n                 * Paint\uac1d\uccb4\ub97c \uc774\uc6a9\ud558\uc5ec \ubc30\uacbd\uc5d0 \ubc11\uc904\uc744 \uadf8\ub9bd\ub2c8\ub2e4\r\n                 *\/\r\n                canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);\r\n            }\r\n            \/\/ \uc218\ud37c \uba54\uc18c\ub4dc\ub97c \ud638\ucd9c\ud558\ub294\uac83\uc73c\ub85c \ub9c8\ubb34\ub9ac \uc9d3\uc2b5\ub2c8\ub2e4.\r\n            super.onDraw(canvas);\r\n        }\r\n    }<\/pre>\n<h1>\ucee4\uc2a4\ud140 \ubdf0 \ud074\ub798\uc2a4 \ub9cc\ub4e4\uae30<\/h1>\n<pre class=\"lang:java decode:true  \">class PieChart extends View {\r\n    public PieChart(Context context, AttributeSet attrs) {\r\n        super(context, attrs);\r\n    }\r\n}<\/pre>\n<p>\uc548\ub4dc\ub85c\uc774\ub4dc \uc2a4\ud29c\ub514\uc624\uc5d0\uc11c \ub808\uc774\uc544\uc6c3 \ud3b8\uc9d1\uae30(layout editor)\uc640 \uc0c1\ud638\uc791\uc6a9 \ud560 \uc218 \uc788\uac8c \ud558\ub824\uba74 \ucd5c\uc18c\ud55c Context\uc640 AttributeSet \uac1d\uccb4\ub97c \ub9e4\uac1c\ubcc0\uc218\ub85c \ucde8\ud558\ub294 \uc0dd\uc131\uc790\ub97c \ub9cc\ub4e4\uc5b4\uc57c\ud569\ub2c8\ub2e4. \uc774 \uc0dd\uc131\uc790\ub97c \uc0ac\uc6a9\ud558\uba74 \ub808\uc774\uc544\uc6c3 \ud3b8\uc9d1\uae30\uc5d0\uc11c \ubdf0\uc758 \uc778\uc2a4\ud134\uc2a4\ub97c \ub9cc\ub4e4\uace0 \ud3b8\uc9d1 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>\ucee4\uc2a4\ud140 \uc18d\uc131 \uc120\uc5b8(Define Custom Attributes)<\/h2>\n<p>xml \uc694\uc18c\ub97c \ud1b5\ud574 View\ub97c \uc81c\uc5b4\ud558\uae30 \uc704\ud574 res\/values\/attrs.xml \ud30c\uc77c\uc5d0 &lt;declare-styleable&gt; \uc694\uc18c\ub97c \ucd94\uac00\ud569\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;resources&gt;\r\n   &lt;declare-styleable name=\"PieChart\"&gt;\r\n       &lt;attr name=\"showText\" format=\"boolean\" \/&gt;\r\n       &lt;attr name=\"labelPosition\" format=\"enum\"&gt;\r\n           &lt;enum name=\"left\" value=\"0\"\/&gt;\r\n           &lt;enum name=\"right\" value=\"1\"\/&gt;\r\n       &lt;\/attr&gt;\r\n   &lt;\/declare-styleable&gt;\r\n&lt;\/resources&gt;<\/pre>\n<p>\ucee4\uc2a4\ud140 \uc18d\uc131\uc778 showText \ubc0f labelPosition\uc744 \uc120\uc5b8\ud55c \ubaa8\uc2b5\uc785\ub2c8\ub2e4.<\/p>\n<p>\uc0ac\uc6a9\uc790 \uc815\uc758 \uc18d\uc131\uc744 \uc815\uc758\ud55c \ud6c4\uc5d0\ub294 \ube4c\ud2b8\uc778 \uc18d\uc131\ucc98\ub7fc \ub808\uc774\uc544\uc6c3 XML \ud30c\uc77c\uc5d0\uc11c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc720\uc77c\ud55c \ucc28\uc774\uc810\uc740 \uc0ac\uc6a9\uc790 \uc9c0\uc815 \ud2b9\uc131\uc774 \ub2e4\ub978 \ub124\uc784\uc2a4\ud398\uc774\uc2a4\uc5d0 \uc18d\ud55c\ub2e4\ub294\uac83\uc785\ub2c8\ub2e4.\u00a0 http:\/\/schemas.android.com\/apk\/res\/android \ub124\uc784 \uc2a4\ud398\uc774\uc2a4\uc5d0 \uc18d\ud558\ub294 \ub300\uc2e0 http:\/\/schemas.android.com\/apk\/res\/ [\ud328\ud0a4\uc9c0 \uc774\ub984]\uc5d0 \uc18d\ud569\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uba74 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:xhtml decode:true \">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n   xmlns:custom=\"http:\/\/schemas.android.com\/apk\/res\/com.example.customviews\"&gt;\r\n &lt;com.example.customviews.charting.PieChart\r\n     custom:showText=\"true\"\r\n     custom:labelPosition=\"left\" \/&gt;\r\n&lt;\/LinearLayout&gt;<\/pre>\n<p>\uae34 \ub124\uc784 \uc2a4\ud398\uc774\uc2a4 URI\ub97c \ubc18\ubcf5\ud558\uc9c0 \uc54a\uc544\ub3c4\ub418\ub3c4\ub85d \uc704\uc758 \uc0d8\ud50c\uc5d0\uc11c\ub294 xmlns \uc9c0\uc2dc\ubb38\uc744 \uc0ac\uc6a9\ud569\ub2c8\ub2e4. \uc774 \uc9c0\uc2dc\ubb38\uc740 \ubcc4\uce6d custom\uc744 http:\/\/schemas.android.com\/apk\/res\/com.example.customviews \ub124\uc784 \uc2a4\ud398\uc774\uc2a4\uc5d0 \ud560\ub2f9\ud569\ub2c8\ub2e4. custom \ub300\uc2e0 \uc6d0\ud558\ub294 \ubcc4\uce6d\uc744 \uc120\ud0dd\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ucee4\uc2a4\ud140\ubdf0 \ud074\ub798\uc2a4\uac00 \ub0b4\ubd80 \ud074\ub798\uc2a4\uc778 \uacbd\uc6b0 \ubdf0\uc758 \uc678\ubd80 \ud074\ub798\uc2a4 \uc774\ub984\uc73c\ub85c \ucd94\uac00\ub85c \uc815\uaddc\ud654\ud574\uc57c\ud569\ub2c8\ub2e4. \ub354\uc6b1\uc774. \uc608\ub97c \ub4e4\uc5b4 PieChart \ud074\ub798\uc2a4\uc5d0\ub294 PieView\ub77c\ub294 \ub0b4\ubd80 \ud074\ub798\uc2a4\uac00 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \ud074\ub798\uc2a4\uc758 \uc0ac\uc6a9\uc790 \uc815\uc758 \uc18d\uc131\uc744 \uc0ac\uc6a9\ud558\ub824\uba74 com.example.customviews.charting.PieChart $ PieView \ud0dc\uadf8\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.<\/p>\n<\/div>\n<h2>\ucee4\uc2a4\ud140 \uc18d\uc131\uc744 \uc801\uc6a9\ud574\ubcf4\uc790<\/h2>\n<p>\ubdf0\uac00 XML \ub808\uc774\uc544\uc6c3\uc73c\ub85c\ubd80\ud130 \uc791\uc131\ub418\uc5c8\uc744 \ub54c, XML \ud0dc\uadf8\uc758 \ubaa8\ub4e0 \uc18d\uc131\uc740 \ub9ac\uc18c\uc2a4 \ubc88\ub4e4\ub85c\ubd80\ud130 \uc77d\uc5b4\uc838 \ubdf0\uc758 \uc0dd\uc131\uc790\uc5d0 AttributeSet\ub85c\uc11c \uac74\ub124\ubc1b\uc2b5\ub2c8\ub2e4. AttributeSet\uc5d0\uc11c \uc9c1\uc811 \uac12\uc744 \uc77d\uc744 \uc218\ub3c4 \uc788\uc9c0\ub9cc \uc774\ub807\uac8c\ud558\uba74 \uba87 \uac00\uc9c0 \ub2e8\uc810\uc774 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<ul>\n<li>\uc18d\uc131\uac12\uc758 \ub9ac\uc18c\uc2a4\ucc38\uc870\uac00 \uc548\ub429\ub2c8\ub2e4.<\/li>\n<li>Style\uc774 \uc801\uc6a9\ub418\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<\/li>\n<\/ul>\n<p>\ub300\uc2e0\uc5d0 AttributeSet\uc744\u00a0obtainStyledAttributes()\uc5d0\uac8c \ub118\uae41\ub2c8\ub2e4. \uc774 \uba54\uc18c\ub4dc\ub294 TypedArray\ub97c \ub3cc\ub824\uc90d\ub2c8\ub2e4.<\/p>\n<p>\uc548\ub4dc\ub85c\uc774\ub4dc \ub9ac\uc18c\uc2a4 \ucef4\ud30c\uc77c\ub7ec\ub294 obtainStyledAttributes()\ub97c \ub354 \uc27d\uac8c \ud638\ucd9c \ud560 \uc218 \uc788\ub3c4\ub85d \ub9ce\uc740 \uc791\uc5c5\uc744 \uc218\ud589\ud569\ub2c8\ub2e4.\u00a0res \ub514\ub809\ud1a0\ub9ac\uc758 \uac01 &lt;declare-styleable&gt; \ub9ac\uc18c\uc2a4\uc5d0 \ub300\ud574 \uc0dd\uc131 \ub41c R.java\ub294 \uc18d\uc131 ID \ubc30\uc5f4\uacfc \ubc30\uc5f4\uc758 \uac01 \uc18d\uc131\uc5d0 \ub300\ud55c \uc778\ub371\uc2a4\ub97c \uc815\uc758\ud558\ub294 \uc0c1\uc218 \uc138\ud2b8\ub97c \ubaa8\ub450 \uc815\uc758\ud569\ub2c8\ub2e4.\u00a0\ubbf8\ub9ac \uc815\uc758 \ub41c \uc0c1\uc218\ub97c \uc0ac\uc6a9\ud558\uc5ec TypedArray\uc5d0\uc11c \ud2b9\uc131\uc744 \uc77d\uc2b5\ub2c8\ub2e4. PieChart \ud074\ub798\uc2a4\uac00 \uadf8 \uc18d\uc131\uc744 \uc77d\ub294 \ubc29\ubc95\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:java decode:true\">public PieChart(Context context, AttributeSet attrs) {\r\n   super(context, attrs);\r\n   TypedArray a = context.getTheme().obtainStyledAttributes(\r\n        attrs,\r\n        R.styleable.PieChart,\r\n        0, 0);\r\n\r\n   try {\r\n       mShowText = a.getBoolean(R.styleable.PieChart_showText, false);\r\n       mTextPos = a.getInteger(R.styleable.PieChart_labelPosition, 0);\r\n   } finally {\r\n       a.recycle();\r\n   }\r\n}<\/pre>\n<p><em>\uc8fc\uc758:TypedArray \uac1d\uccb4\ub294 \uacf5\uc720 \ub9ac\uc18c\uc2a4\uc774\uae30 \ub54c\ubb38\uc5d0 \ubc18\ub4dc\uc2dc \uc0ac\uc6a9\ud6c4\uc5d0 recycle() \ud574\uc57c\ud569\ub2c8\ub2e4.<\/em><\/p>\n<h2>\uc18d\uc131 \ubc0f \uc774\ubca4\ud2b8 \ucd94\uac00\ud558\uae30<\/h2>\n<p>\uc18d\uc131\uc740 \ubdf0\uc758 \ub3d9\uc791 \ubc0f \ubaa8\uc591\uc744 \uc81c\uc5b4\ud558\ub294 \uac15\ub825\ud55c \ubc29\ubc95\uc774\uc9c0\ub9cc View\uac00 \ucd08\uae30\ud654 \ub420\ub54c\ub9cc \uc77d\uc744 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub3d9\uc801\uc73c\ub85c \uc774\ub97c \uc81c\uc5b4\ud558\ub824\uba74 \uac01 \uc0ac\uc6a9\uc790 \uc815\uc758 \uc18d\uc131\uc5d0 \ub300\ud55c getter\uc640 setter\ub97c \uc30d\uc73c\ub85c \uc81c\uacf5\ud574\uc57c\ud569\ub2c8\ub2e4. \ub2e4\uc74c \uc2a4\ub2c8\ud3ab\uc740 PieChart\uac00 showText\ub77c\ub294 \uc18d\uc131\uc744 \ub178\ucd9c\ud558\ub294 \ubc29\ubc95\uc744 \ubcf4\uc5ec\uc90d\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:java decode:true \">public boolean isShowText() {\r\n   return mShowText;\r\n}\r\n\r\npublic void setShowText(boolean showText) {\r\n   mShowText = showText;\r\n   invalidate();\r\n   requestLayout();\r\n}<\/pre>\n<p>setShowText\ub294 \uae00\ub85c\ubc8c\ubcc0\uc218 mShowText\uc5d0 \uac12\uc744 \ub300\uc785\ud55c \ub4a4\u00a0 invalidate () \ubc0f requestLayout ()\uc744 \ud638\ucd9c\ud569\ub2c8\ub2e4. \uc774\ub7ec\ud55c \ud638\ucd9c\uc740 View\uac00 \uc548\uc815\uc801\uc73c\ub85c \uc791\ub3d9\ud558\ub3c4\ub85d\ud558\ub294 \ub370 \uc911\uc694\ud569\ub2c8\ub2e4. \ubaa8\uc591\uc744 \ubcc0\uacbd\ud560 \uc218\uc788\ub294 \uc18d\uc131\uc744 \ubcc0\uacbd \ud55c \ud6c4\uc5d0 \ubdf0\ub97c \ubb34\ud6a8\ud654\ud574\uc57c \uc2dc\uc2a4\ud15c\uc5d0\uc11c \ub2e4\uc2dc \uadf8\ub824\uc57c \ud568\uc744 \uc54c \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub9c8\ucc2c\uac00\uc9c0\ub85c View\uc758 \ud06c\uae30 \ub098 \ubaa8\uc591\uc5d0 \uc601\ud5a5\uc744 \uc904 \uc218\uc788\ub294 \uc18d\uc131\uc774 \ubcc0\uacbd\ub41c \uacbd\uc6b0 \uc0c8 \ub808\uc774\uc544\uc6c3\uc744 \uc694\uccad\ud574\uc57c\ud569\ub2c8\ub2e4. \uc774\ub7ec\ud55c \uba54\uc18c\ub4dc \ud638\ucd9c\uc744 \uc78a\uc5b4 \ubc84\ub9ac\uba74 \ucc3e\uae30 \ud798\ub4e0 \ubc84\uadf8\uac00 \ubc1c\uc0dd\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ucee4\uc2a4\ud140 \ubdf0 \ub9cc\ub4e4\uae30 \ucee4\uc2a4\ud140\ubdf0\ub294 \uc65c \ud544\uc694\ud560\uae4c? \uc548\ub4dc\ub85c\uc774\ub4dc \ud504\ub808\uc784\uc6cc\ud06c\uc5d0\uc11c \uae30\ubcf8 \uc81c\uacf5\ub418\ub294 \uc704\uc82f\ub4e4\ub85c\ub294 Button, TextView, EditText, ListView, CheckBox, RadioButton, Spinner \ub4f1\uc774 \uc788\uace0 \ub808\uc774\uc544\uc6c3\uc73c\ub85c\ub294 LinearLayout, FrameLayout, RelativeLayout \ub4f1\uc774 \uc788\uc2b5\ub2c8\ub2e4. \ud558\uc9c0\ub9cc \uc2e4\uc81c\ub85c \uc571\uc744 \ub9cc\ub4e4\ub2e4 \ubcf4\uba74 \uae30\ud68d\uc790, \ub514\uc790\uc774\ub108, \uc0ac\uc6a9\uc790(\ud074\ub77c\uc774\uc5b8\ud2b8)\uc758 \uc694\uad6c\uc0ac\ud56d\uc5d0 \ub9de\ub294 \uae30\ub2a5\uc744 \uc704\uc758 \uc5f4\uac70\ud55c \ubdf0\ub4e4\ub85c \ub9cc\ub4e4\uae30 \uc5b4\ub835\uac70\ub098 \ubd88\uac00\ub2a5\ud55c \uacbd\uc6b0\uac00 \ubd80\uc9c0\uae30\uc218\uc785\ub2c8\ub2e4.\u00a0 \uc608\ub97c\ub4e4\uba74, \uc6d0\ud615 \uc378\ub124\uc77c\uc744 \ud45c\ud604\ud558\uae30 \uc704\ud55c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[16],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/1035"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1035"}],"version-history":[{"count":1,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/1035\/revisions"}],"predecessor-version":[{"id":1036,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/1035\/revisions\/1036"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}