0

I have CircleView custom object, that works fine.

enter image description here

I want to compound it with a TextView below, like this:

enter image description here

So I made CircleCheckBoxWithText that compound the two views,

The problem is that if the first view that I'm adding is my custom view, and the second view is the TextView, I can't see the TextView.

(When the first view that I'm adding is the TextView and the second is my custom view, I can see both views)

CircleView:

public class CircleView extends View
{
    private float mDimension;
    private int mFillColor;
    private int mBorderColor;
    private boolean mIsChecked;
    private Paint mFillPaint = new Paint();
    private Paint mStrokePaint = new Paint();

    public CircleView(Context context)
    {
        super(context);
    }

    public CircleView(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
    }

    public CircleView(Context context, AttributeSet attrs)
    {
        super(context, attrs);

        // Get the styledAttributes from the xml
        TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CircleView, 0, 0);

        try
        {
            mDimension = styledAttributes.getDimensionPixelOffset(R.styleable.CircleView_dim, 20);
            mFillColor = styledAttributes.getColor(R.styleable.CircleView_fill_color, Color.WHITE);
            mBorderColor = styledAttributes.getColor(R.styleable.CircleView_border_color, Color.WHITE);
            mIsChecked = styledAttributes.getBoolean(R.styleable.CircleView_checked, false);
        }
        finally
        {
            styledAttributes.recycle();
        }
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        super.onDraw(canvas);

        // init canvas
        canvas.drawARGB(0, 0, 0, 0);

        // Set the Fill
        mFillPaint.setAntiAlias(true);
        mFillPaint.setDither(true);
        mFillPaint.setColor(mFillColor);

        // Set the Stroke
        mStrokePaint.setAntiAlias(true);
        mStrokePaint.setDither(true);
        mStrokePaint.setColor(mBorderColor);
        mStrokePaint.setStyle(Paint.Style.STROKE);
        mStrokePaint.setStrokeWidth(8f);

        canvas.drawCircle(mDimension / 2, mDimension / 2, mDimension / 2 - 0.2f, mFillPaint);

        if(mIsChecked)
        {
             canvas.drawCircle(mDimension / 2, mDimension / 2, mDimension / 2 - mStrokePaint.getStrokeWidth() / 2 + 0.1f, mStrokePaint);
        }
    }
}

CircleCheckBoxWithText:

public class CircleCheckBoxWithText extends LinearLayout
{
    public CircleCheckBoxWithText(Context context)
    {
        super(context);
        setOrientation(VERTICAL);
    }

    public CircleCheckBoxWithText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        setOrientation(VERTICAL);

        addView(new CircleView(context, attrs));
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setText("TEST");
        addView(textView);
    }

    public CircleCheckBoxWithText(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
        setOrientation(VERTICAL);
    }
}
David
  • 37,109
  • 32
  • 120
  • 141

0 Answers0