ScrollView Layout does not fill the whole screen

后端 未结 5 2044
一整个雨季
一整个雨季 2021-01-31 06:54

I got an Activity with two Fragments (one list one normal). And the normal Fragment inflates a Scrollview containing a

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 07:24

    I had a similar problem and could only fix it with a Helper Class. I found the original code online and this is my implementation of it.

    Java class:

    public class ImageViewHelper extends android.support.v7.widget.AppCompatImageView {
    
        public ImageViewHelper(Context context) {
            super(context);
        }
    
        public ImageViewHelper(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public ImageViewHelper(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            Drawable d = getDrawable();
            if (d != null) {
                int w = MeasureSpec.getSize(widthMeasureSpec);
                int h = w * d.getIntrinsicHeight() / d.getIntrinsicWidth();
                setMeasuredDimension(w, h);
            }
            else super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }
    

    XML:

    
    

提交回复
热议问题