I am currently facing the same problem.
I am trying to do something like this because the ViewParent has the actual height set explicitly, so I use match_parent and set the fields. This does not work all the time, because I just use this view in the viewer for RecyclerView ... I also noticed that sometimes I see an extended version with artifacts, sometimes in full size, sometimes there are fields and more fields ... But itβs all Equally may work for you if you use it in a simpler scenario.
mImageViewFront.setImageDrawable(vectorDrawable); final int paddingLR = mImageViewFront.getWidth() / 4; final int paddingTB = mImageViewFront.getHeight() / 4; LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); params.setMargins(paddingLR, paddingTB, paddingLR, paddingTB); mImageViewFront.setLayoutParams(params);
source share