Search code examples
androidlayoutcustom-view

Adding a Custom ImageView to main layout


here is the deal.

i was looking over this code about extending an ImageView:

http://marakana.com/forums/android/examples/98.html

and i was wondering how can i add the new View to an existing xml layout file, along with some other views.

already i did this inside my main linear layout:

<FrameLayout android:id="@+id/FrameLayout01" android:layout_width="300dp" android:layout_height="300dp">
        <com.marakana.Rose android:layout_height="wrap_content" android:layout_width="wrap_content"/>

but the problem is that this way the onDraw method doesn't get called.

can anyone suggest a solution for this? maybe some examples where you combine CustomViews with xml layout.

tnx.


Solution

  • I think I solved it. I used my code in the main.xml file and it works. the thing I had to do was to override a new class constructor accepting AttributesSet alongside with the context as a parameter and then use findViewById(CustomViewName) to reference it in the activity and use the functions defined in the CustomView.