[問題] 如何將繼承view的class顯示在layout上?
在繼承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)
推
10/09 00:10, , 1F
10/09 00:10, 1F
→
10/09 02:30, , 2F
10/09 02:30, 2F
→
10/09 02:30, , 3F
10/09 02:30, 3F
→
10/09 02:30, , 4F
10/09 02:30, 4F
→
10/09 02:33, , 5F
10/09 02:33, 5F
我是在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)
→
10/09 13:32, , 6F
10/09 13:32, 6F
回c大,只有ViewClass(Context context)但加入ViewClass(Context , AttributeSet)
就可以了....可以請問是差在哪裡嗎?謝謝C大
※ 編輯: AZHI 來自: 123.205.97.25 (10/10 08:11)
→
10/10 19:45, , 7F
10/10 19:45, 7F
→
10/11 01:34, , 8F
10/11 01:34, 8F
→
10/11 01:34, , 9F
10/11 01:34, 9F
→
10/11 01:35, , 10F
10/11 01:35, 10F
謝謝c大和l大的回答
※ 編輯: AZHI 來自: 1.168.202.149 (10/11 22:14)