看板 AndroidDev 關於我們 聯絡資訊
在繼承view的class中 使用onDraw()繪圖 程式碼: public class MyView extends View { ............. ............. protected void onDraw(Canvas canvas) { ........... ........... } } 然後,在main.xml中新增一個FrameLayout 請問板上大大 如何將class中所畫的東西顯示在FrameLayout中呢? 備註:class是有觸控的繪圖功能 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.205.97.25 ※ 編輯: AZHI 來自: 123.205.97.25 (10/09 00:02)
zxc190:.addView...? 10/09 00:10
cooper6334:要在xml加的話要打整個class的全名並且實作 10/09 02:30
cooper6334:建構子(Context,AttributeSet) 10/09 02:30
cooper6334:不然就是如1樓說的在程式裡用AddView加 10/09 02:30
cooper6334:還是你的問題是畫不出來??? 10/09 02:33
我是在xml的layout中加入view <view class="com.example.canvasdraw.ViewClass"←這邊是我的CLASS android:layout_width="fill_parent" android:layout_height="fill_parent" /> 但無法顯示出來,執行後會跳出 不知道原因為何... ※ 編輯: AZHI 來自: 123.205.97.25 (10/09 12:47)
cooper6334:你有實作ViewClass(Context , AttributeSet)嗎?log呢? 10/09 13:32
回c大,只有ViewClass(Context context)但加入ViewClass(Context , AttributeSet) 就可以了....可以請問是差在哪裡嗎?謝謝C大 ※ 編輯: AZHI 來自: 123.205.97.25 (10/10 08:11)
cooper6334:http://ppt.cc/3AWU 10/10 19:45
ljhgc:android:layout_width這些屬性在建構時會透過AttributeSet傳 10/11 01:34
ljhgc:入class,所以你要實作ViewClass(Context , AttributeSet) 10/11 01:34
ljhgc:如果你是在程式裡用AddView加則不用實作這個建構子 10/11 01:35
謝謝c大和l大的回答 ※ 編輯: AZHI 來自: 1.168.202.149 (10/11 22:14)