代码之家  ›  专栏  ›  技术社区  ›  user112016322

是否将ImageView添加到无线电组的左侧?

  •  0
  • user112016322  · 技术社区  · 8 年前

    我正在尝试将ImageView添加到RadioGroup。最好作为RadioGroup的一部分,但位于组内所有RadioButtons的左侧。我可以通过简单地将其添加为最后一项来将其显示在底部,但我希望它显示在左侧。

    请参阅下面的代码和图片。

    使其显示在底部的代码:

    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);
    

    图片:

    enter image description here

    任何帮助都将不胜感激。非常感谢。

    2 回复  |  直到 8 年前
        1
  •  0
  •   F43nd1r    8 年前

    RadioGroup 继承自 LinearLayout 。这意味着它只支持在下面放置视图 彼此的权利。

    如果你想要两者,你必须把你的 单选 在另一个里面 ViewGroup 例如 RelativeLayout .

        2
  •  0
  •   tiny sunlight    8 年前
    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(0,errorImage);
    errorImage.setTranslationY(100);
    LayoutParams  params = new Layoutparams(100,100);
    params.gravity = Gravity.RIGHT;
    rg.getChildAt(1).setLayoutParams(params)