0

创建自定义视图组时,是否可以在其中包含多个图像按钮?是否可以将图像按钮放置在我们自己的位置。

如果所有这些都是可能的,如何调用扩展这个视图组的点击监听器?

我的 ViewGroup 必须看起来像这张图片 在此处输入图像描述

编辑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();

    }

我正在尝试绘制背景并将一些 ImageView 放在背景的顶部。在此代码中,背景图像正在正确显示。但我看不到在其上绘制的 ImageView。我走的是正确的道路吗?

4

1 回答 1

1

你说的一切都是可能的。

你只是用

yourViewGroup.setOnClickListener()

为您的视图组单击侦听器。

于 2011-09-21T08:31:09.433 回答