में आकर्षित नहीं करता है मैं इस तरह एक कस्टम दृश्य CircleView बनाया:कैनवास कस्टम दृश्य
<com.turkidroid.test.CircleView
android:id="@+id/circle_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" />
हालांकि, कुछ भी नहीं तैयार किया गया था:
public class CircleView extends LinearLayout {
Paint paint1;
public CircleView(Context context) {
super(context);
init();
}
public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public void init() {
paint1 = new Paint();
paint1.setColor(Color.RED);
}
protected void onDraw(Canvas canvas) {
//super.onDraw(canvas);
canvas.drawCircle(50, 50, 25, paint1);
this.draw(canvas);
}
}
तो मैं इसे अपने गतिविधि के लेआउट जड़ <RelativeLayout>
पर शामिल!
- क्या मैं कस्टम दृश्य को लागू कर रहा हूं?
- या यह है कि मैंने कस्टम व्यू का उपयोग कैसे किया?
कुछ जानकारी:
- दोनों CircleView और MyActivity एक ही पैकेज में कर रहे हैं:
com.turkidroid.test
। onDraw()
विधि में, मैंनेsuper.onDraw()
सहित टिप्पणी की और इसे टिप्पणी की।- मुझे पता है कि मैं बहुत सरल दृष्टिकोण के साथ एक सर्कल खींच सकता हूं लेकिन मेरा सर्किल व्यू में एक सर्कल ड्राइंग से अधिक होता है। मुझे इसे कस्टम व्यू बनाने की ज़रूरत है।
यह फेंकता 'java.lang.StackOverflowError' मैं कंस्ट्रक्टर्स के लिए विधि जोड़ा के बाद! कोई विचार? – iTurki
आपके सुझाव से मैंने आपके कोड से super.onDraw() 'पर टिप्पणी नहीं की है, तो आपके सुझाव ने एक आकर्षण की तरह काम किया। धन्यवाद! – iTurki
मुझे यकीन नहीं है कि यह क्या था, मेरा सुपर .न्ड्रा कॉल गायब था और उपरोक्त झंडा भी डिफ़ॉल्ट रूप से सेट किया गया था, लेकिन दोनों जादू में डालने के बाद !!^_^ –