Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

December 22 2011

schlingel

Android: Drawing slider onMeasure content size sensitive

	    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
	        int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
	        int widthSpecSize =  MeasureSpec.getSize(widthMeasureSpec);

	        int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
	        int heightSpecSize =  MeasureSpec.getSize(heightMeasureSpec);

	        if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
	            throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
	        }

	        final View handle = getHandle();
	        final View content = getContent();
	        measureChild(handle, widthMeasureSpec, heightMeasureSpec);

	        if (vertical) {
	            int height = heightSpecSize - handle.getMeasuredHeight() - topOffset;
	            content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
	            heightSpecSize = handle.getMeasuredHeight() + topOffset + content.getMeasuredHeight();
	            widthSpecSize = content.getMeasuredWidth();
	            if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
	        }
	        else {
	            int width = widthSpecSize - handle.getMeasuredWidth() - topOffset;
	            getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
	            widthSpecSize = handle.getMeasuredWidth() + topOffset + content.getMeasuredWidth();
	            heightSpecSize = content.getMeasuredHeight();
	            if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();
	        }

	        setMeasuredDimension(widthSpecSize, heightSpecSize);
	    }	
Reposted byurfin urfin

Don't be the product, buy the product!

Schweinderl