Search code examples
androidandroid-custom-view

Custom view with children inside it(buttons, edittexts, etc.)


I have custom view which extends imageview (with glow touch). I want to add elements like buttons, textviews, to make glow touch when they are touched. I read that custom view cannot have children because only layouts can have them.

Is there any workaround to solve this stuff?

Code:

public class CustomView extends ImageView{
    public CustomView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomView(Context context) {
        super(context);

    .........

    }

With regards


Solution

  • You are correct about the fact that only layouts (ViewGroups) can contain Views, and Views itself can not.

    Instead of making a custom View, you can make a custom ViewGroup. In there you can add the Views you need, like the ImageViews and the others you mention (Buttons, EditText, etc).