PercentRelativeLayout inside ScrollView

后端 未结 4 1980
忘掉有多难
忘掉有多难 2021-01-07 22:58

I have created a layout using a ScrollView which has a PercentRelativeLayout as its child. It doesn\'t work on Lollipop and older devices but works

4条回答
  •  迷失自我
    2021-01-07 23:00

    Create one custom scrollview and set Measured Height and Width as you want to it for Example

    CustomScrollView

    public class CustomScrollView extends ScrollView {
    
    
        public CustomScrollView(Context context) {
            super(context);
        }
    
        public CustomScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            int size = 0;
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
    
            if (width > height) {
                size = height;
            } else {
                size = width;
            }
            setMeasuredDimension(size, size);
        }
    }
    

    Use customscrollview in your xml.

        
    
    

    hope this will help.

提交回复
热议问题