मैं एंड्रॉइड पर एक कस्टम View
बनाना चाहता हूं। मैंने इसे यथासंभव सरल करने की कोशिश की है और लगभग खाली कक्षा MyView
बनाई है और इसे अपने LinearLayout
में उपयोग किया है लेकिन एप्लिकेशन "फोर्स क्लोज़" से शुरू होने में विफल रहता है। मैं एक साधारण कस्टम View
कैसे कर सकता हूं? Building Custom Components के अनुसार View
आकार 100x100 प्राप्त करता है यदि मैं onMeasure()
ओवरराइड नहीं करता हूं।एक साधारण कस्टम व्यू कैसे बनाएं?
public class MyView extends View {
public MyView(Context context) {
super(context);
}
}
और मैं एक LinearLayout
में उपयोग के साथ:
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0" />
क्या मैं गलत कर रहा हूँ?
अगर मैं निर्माता है कि सुझाव है itemon और सुपर क्लास के लिए इसी कॉल का उपयोग करें। फिर "फोर्स क्लोज़" चला गया है, लेकिन मेरा LinearLayout
टूटा हुआ है, MyView
के बाद के घटक नहीं दिखाए गए हैं।
यहाँ मेरी main.xml
है:
public MyView(Context context, AttributeSet attrs)
एंड्रॉयड ढांचे ऊपर निर्माता से अपने दृश्य के साथ यूआई का निर्माण करने की कोशिश करेंगे:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#f00"
android:text="Hello"
/>
<view
class="com.example.MyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:background="#00f"
android:text="World"
/>
</LinearLayout>
आप यहां एक अच्छे नमूने से परामर्श कर सकते हैं: [http://www.sgoliver.net/blog/?p=1457 ](http://www.sgoliver.net/blog/?p=1457) –
मुझे समान जरूरत है .. क्या आपको वह चाहिए जो आपको चाहिए। कुछ कोड कृपया देखें – Nepster