Question

While creating a custom Viewgroup,is it possible to have multiple Imagebutton within it? is it possible to place Image buttons in our own position.

If all these are possible,how to call the click listener which extending this viewgroup?

My ViewGroup have to look like this image enter image description here

EDIT 1:

public class CustomViewGroup extends ViewGroup{

    public CustomViewGroup(Context context) {
        super(context);
        setWillNotDraw(false);
        //addImageView();
        // TODO Auto-generated constructor stub
    }
    public CustomViewGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        setWillNotDraw(false);
        //addImageView();
        // TODO Auto-generated constructor stub
    }
    public CustomViewGroup(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, 
                defStyle);
        setWillNotDraw(false);
        //addImageView();
        // TODO Auto-generated constructor stub
    }
    @Override
    protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
        // TODO Auto-generated method stub
        System.out.println("onLayout");
    }
    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        drawBackground(canvas);
        addImageView();
        //super.onDraw(canvas);
    }

    private void drawBackground(Canvas canvas)
    {
        Bitmap background =BitmapFactory.decodeResource(getContext().getResources(), R.drawable.shape_quarter_circle);
        canvas.drawBitmap(background, 0,0, null);
    }
    private void addImageView()
    {
        ImageView imageOne = new ImageView(getContext());
        imageOne.setImageDrawable(getContext().getResources().getDrawable(R.drawable.round_icon));
        //imageOne.setWillNotDraw(false);
        addView(imageOne);
        requestLayout();

    }

I am trying to draw a background and place some ImageView on the top of the background. In this code Background image is getting displayed correctly. but i could not see the ImageView drawn upon it. Am i going in the correct path?

Was it helpful?

Solution

all the things you said are possible.

you just use

yourViewGroup.setOnClickListener()

for your view group click listener.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top