Search code examples
javaandroidandroid-relativelayoutradio-group

Adding ImageView to the left of the radio group?


I'm trying to add an ImageView to a RadioGroup. Preferably as part of the RadioGroup but to the left of all of the RadioButtons that are inside the group. I can make it appear on the bottom by simply adding it as the last item, but I would like to get it to appear to the left.

See my code and a picture below.

Code for getting it to appear on bottom:

RadioGroup rg = (RadioGroup) currentLayout.findViewWithTag("rg" + fld_id);

errorImage = new ErrorImageView(this);
errorImage.setBackgroundResource(R.mipmap.redxsmall);
errorImage.setScaleX(0.8f);
errorImage.setScaleY(0.8f);

rg.addView(errorImage);

Picture:

enter image description here

Any help would be appreciated. Thank you.


Solution

  • RadioGroup inherits from LinearLayout. That means it only supports placing views below or right of each other.

    If you want both you have to wrap your RadioGroup inside another ViewGroup, e.g. a RelativeLayout.