20.11.2016 Views

ANDROID APP

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

282 บทที่ 11 เทคนิคขั้นสูงสำาหรับพัฒนาแอพบนแอนดรอยด์<br />

}<br />

mTextPaint.measureText(mText),<br />

this.getHeight()-(this.getHeight()-mTextPaint.getTextSize())/2);<br />

drawArcs(canvas, drawRect, false, mPaint);<br />

mSweep += SWEEP_INC;<br />

if (mSweep > 360) {<br />

mSweep -= 360;<br />

mStart += START_INC;<br />

if (mStart >= 360) {<br />

mStart -= 360;<br />

}<br />

}<br />

if(mSweep >180){<br />

canvas.drawText(mText, getPaddingLeft(),<br />

getPaddingTop() -mAscent, mTextPaint);<br />

}<br />

invalidate();<br />

ชุดคำสั่งที่ 11.2 จะแสดงเลย์เอาต์ที่มีการใช้ปุ่มที่สร้างขึ้นเอง<br />

ชุดคำสั่งที่ 11.2 res/layout/main.xml<br />

<br />

<br />

<br />

<br />

ในไฟล์เลย์เอาต์ XML จะมี ViewGroup, LinearLayout และ View เพียงอย่างละหนึ่งตัว<br />

ซึ่งสามารถอ้างอิงถึงปุ่มที่สร้างขึ้นด้วยคำสั่ง com.cookbook.advance.customComponent.<br />

myButton และสามารถนำมาใช้งานภายในแอคทิวิตี้ได้ ดังแสดงไว้ในชุดคำสั่งที่ 11.3<br />

ชุดคำสั่งที่ 11.3 src/com/cookbook/advance/ShowMyButton.java<br />

package com.cookbook.advance.customComponent;<br />

import android.app.Activity;<br />

import android.os.Bundle;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!