ImageView adjustViewBounds not working with Relative Layout

后端 未结 2 1738
滥情空心
滥情空心 2021-02-20 07:30

I have an ImageView and have set its layout_height to \"100dp\" and its layout_width to \"wrap_content\".

The drawable used has bigger actual

2条回答
  •  遥遥无期
    2021-02-20 08:26

    use width and height of imageview to match_parent

    private void addView(Drawable d) {
        RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,     RelativeLayout.LayoutParams.MATCH_PARENT);
        ImageView iv = new ImageView(this);
        iv.setImageDrawable(d);
        iv.setAdjustViewBounds(true);
        iv.setScaleType(ImageView.ScaleType.MATRIX);
        iv.setLayoutParams(lparams);
        rl.addView(iv);
        iv.setOnTouchListener(this);
    }
    

提交回复
热议问题