/** * Sets the layout resource for a custom MarkerView. * * @param layoutResource */ private void setupLayoutResource(int layoutResource) { View inflated = LayoutInflater.from(getContext()).inflate(layoutResource, this); inflated.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); inflated.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); // measure(getWidth(), getHeight()); inflated.layout(0, 0, inflated.getMeasuredWidth(), inflated.getMeasuredHeight()); }
@Override protected void onMeasure(int widthSpec, int heightSpec) { int fourThreeHeight = makeMeasureSpec(getSize(widthSpec) * 3 / 4, EXACTLY); super.onMeasure(widthSpec, fourThreeHeight); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.setMeasuredDimension(getSize(widthMeasureSpec), getSize(heightMeasureSpec)); final View waveView = mWaveView; final View circleView = mCircleView; final Drawable progress = mProgress; final int circleDiameter = progress.getIntrinsicWidth(); final int spec = MeasureSpec.makeMeasureSpec(circleDiameter, MeasureSpec.EXACTLY); circleView.measure(spec, spec); waveView.measure(makeMeasureSpec(getSize(widthMeasureSpec), EXACTLY),makeMeasureSpec(getSize(heightMeasureSpec), EXACTLY)); }
private LithoView getLithoView(ComponentTree componentTree) { LithoView lithoView = new LithoView(mContext); lithoView.setComponentTree(componentTree); lithoView.measure( View.MeasureSpec.makeMeasureSpec(HOST_WIDTH, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(HOST_HEIGHT, View.MeasureSpec.EXACTLY)); lithoView.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight()); return lithoView; } }
@Test public void testCorrectsDoubleMeasureBugWithAtMost() { mLithoView = setupLithoViewForDoubleMeasureTest(411, 2.625f, 1080); mLithoView.measure(makeMeasureSpec(1079, AT_MOST), makeMeasureSpec(100, EXACTLY)); assertThat(mLithoView.getMeasuredWidth()).isEqualTo(1080); assertThat(mLithoView.getMeasuredHeight()).isEqualTo(100); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (forceSize != null) { super.onMeasure(MeasureSpec.makeMeasureSpec(forceSize.width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(forceSize.height, MeasureSpec.EXACTLY)); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightMode = View.MeasureSpec.getMode(heightMeasureSpec); if(heightMode == View.MeasureSpec.UNSPECIFIED){ if(mItemHeight != ViewGroup.LayoutParams.WRAP_CONTENT) heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(mItemHeight * getAdapter().getCount() + getPaddingTop() + getPaddingBottom(), View.MeasureSpec.EXACTLY); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final View imageView = mImageView; final View dropView = mWaterDropView; LayoutParams lpImage = (LayoutParams) imageView.getLayoutParams(); imageView.measure( makeMeasureSpec(lpImage.width, EXACTLY), makeMeasureSpec(lpImage.height, EXACTLY) ); dropView.measure( makeMeasureSpec(getSize(widthMeasureSpec), AT_MOST), heightMeasureSpec ); int maxWidth = Math.max(imageView.getMeasuredWidth(), dropView.getMeasuredWidth()); int maxHeight = Math.max(imageView.getMeasuredHeight(), dropView.getMeasuredHeight()); super.setMeasuredDimension(View.resolveSize(maxWidth, widthMeasureSpec), View.resolveSize(maxHeight, heightMeasureSpec)); }
private void layout(View view, int width, int height) { view.layout(0, 0, width, height); view.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST)); view.layout(0, 0, width, height); } }
/** * This will make sure the view falls back to the ViewParams/Max/Or Config if wrap content so that it is never * shrunk to the first image size. In this case it falls back to the config size * * @throws Exception */ @Test public void testGetImageSizeScaleTo_dontUseImageActualSizeWithWrapContent() throws Exception { //Set it to wrap content so that it will fall back to mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY)); // We layout the view to give it a width and height mView.layout(0, 0, 200, 200); ImageSize expected = new ImageSize(500, 500); ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(500, 500)); Assertions.assertThat(result).isNotNull().isEqualsToByComparingFields(expected); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (isWidthHeightEqual() && getWidth() > 0 && getHeight() > 0) { int max = Math.max(getWidth(), getHeight()); int measureSpec = MeasureSpec.makeMeasureSpec(max, MeasureSpec.EXACTLY); super.onMeasure(measureSpec, measureSpec); return; } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
@Test public void onMeasure_shouldNotLayout() throws Exception { assertThat(frameLayout.getHeight()).isEqualTo(0); assertThat(frameLayout.getWidth()).isEqualTo(0); frameLayout.measure(View.MeasureSpec.makeMeasureSpec(150, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.AT_MOST)); assertThat(frameLayout.getHeight()).isEqualTo(0); assertThat(frameLayout.getWidth()).isEqualTo(0); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int targetWidth = ObservableGridView.this.getMeasuredWidth() - ObservableGridView.this.getPaddingLeft() - ObservableGridView.this.getPaddingRight(); widthMeasureSpec = MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.getMode(widthMeasureSpec)); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
public static int measureViewHeight(View view) { ViewGroup.LayoutParams p = view.getLayoutParams(); if (p == null) { p = new ViewGroup.LayoutParams(MATCH_PARENT,WRAP_CONTENT); } int childHeightSpec; int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width); if (p.height > 0) { childHeightSpec = View.MeasureSpec.makeMeasureSpec(p.height, View.MeasureSpec.EXACTLY); } else { childHeightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); } view.measure(childWidthSpec, childHeightSpec); return view.getMeasuredHeight(); }
@Override protected void onMeasure(int widthSpec, int heightSpec) { int fourThreeHeight = makeMeasureSpec(getSize(widthSpec) * 3 / 4, EXACTLY); super.onMeasure(widthSpec, fourThreeHeight); } }
@Override protected void onMeasure(int widthSpec, int heightSpec) { int fourThreeHeight = makeMeasureSpec(getSize(widthSpec) * 3 / 4, EXACTLY); super.onMeasure(widthSpec, fourThreeHeight); }
@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.setMeasuredDimension(getSize(widthMeasureSpec), getSize(heightMeasureSpec)); final View circleView = mCircleView; circleView.measure(MeasureSpec.makeMeasureSpec(mCircleDiameter, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(mCircleDiameter, MeasureSpec.EXACTLY)); // setMeasuredDimension(resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec), // resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec)); }
@Test public void testGetImageSizeScaleTo_useImageActualSize() throws Exception { // We layout the view to give it a width and height mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY)); mView.layout(0, 0, 200, 200); ImageSize expected = new ImageSize(200, 200); ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590)); Assertions.assertThat(result).isNotNull(); Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth()); Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight()); }
@Before public void setUp() throws Exception { mActivity = new Activity(); // Make and set view with some prelim values to test mView = new TestImageView(mActivity); mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY)); mImageAware = new ImageViewAware(mView); }
@Override public void refreshContent(Entry e, Highlight highlight) { measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); layout(0, 0, getMeasuredWidth(), getMeasuredHeight()); }