ImageView adjustViewBounds not working with Relative Layout

后端 未结 2 1788
滥情空心
滥情空心 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:02
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxHeight="100dp"
    android:adjustViewBounds="true"
    

    I got it there

    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
提交回复
热议问题