LuxuryMode
LuxuryMode

Reputation: 33741

custom imageview in larger layout

Having a bit of trouble here. I've created a custom ImageView by subclassing ImageView and I'm able to get it to display if I simply instantiate my view and set the entire contentView of my activity to my imageview via setContentView(myCustomImageView)

But what if I want to just use my custom imageview as part of a larger layout? E.g., I want a button, a textview, etc and then my ImageView somewhere in there...

I tried doing something like programatically creating a linearlayout and then instantiating my special imageview and adding it via mLinearLayout.addView(myCustomImageView) but it crashes when I do this.

Am I missing something basic here?

EDIT: apparently you just use the full namespace of your custom view in the XML.

Upvotes: 0

Views: 435

Answers (1)

Iulius Curt
Iulius Curt

Reputation: 5104

Why don't you put your layout in the XML?

You can add you custom View like this:

<view
    class="com.your_package.myCustomImageView" 
    id="@+id/customView"
/>

You can find more useful resources on the Android SDK documentation site

Edit: Yes, you must use the entire namespace for your self defined views. For standard views you can omit com.android.widget because the SDK knows where to find them, but for your own stuff he doesn't.

Upvotes: 2

Related Questions