com.bumptech.glide.request.target.ViewTarget.getSize()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中com.bumptech.glide.request.target.ViewTarget.getSize()方法的一些代码示例,展示了ViewTarget.getSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ViewTarget.getSize()方法的具体详情如下:
包路径:com.bumptech.glide.request.target.ViewTarget
类名称:ViewTarget
方法名:getSize

ViewTarget.getSize介绍

[英]Determines the size of the view by first checking android.view.View#getWidth() and android.view.View#getHeight(). If one or both are zero, it then checks the view's LayoutParams. If one or both of the params width and height are less than or equal to zero, it then adds an android.view.ViewTreeObserver.OnPreDrawListener which waits until the view has been measured before calling the callback with the view's drawn width and height.
[中]通过首先检查android来确定视图的大小。看法查看#getWidth()和android。看法查看#getHeight()。如果其中一个或两个都为零,则会检查视图的LayoutParams。如果一个或两个参数的宽度和高度都小于或等于零,则会添加一个android。看法ViewTreeObserver。OnPreDrawListener,它在使用视图绘制的宽度和高度调用回调之前等待视图被测量。

代码示例

代码示例来源:origin: bumptech/glide

@Test
public void testDoesNotAddMultipleListenersIfMultipleCallbacksAreAdded() {
 SizeReadyCallback cb1 = mock(SizeReadyCallback.class);
 SizeReadyCallback cb2 = mock(SizeReadyCallback.class);
 target.getSize(cb1);
 target.getSize(cb2);
 assertThat(shadowObserver.getPreDrawListeners()).hasSize(1);
}

代码示例来源:origin: bumptech/glide

@Test
public void testDoesNotNotifyCallbackTwiceIfAddedTwice() {
 target.getSize(cb);
 target.getSize(cb);
 view.setLayoutParams(new LayoutParams(100, 100));
 shadowView.setIsLaidOut(true);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb, times(1)).onSizeReady(anyInt(), anyInt());
}

代码示例来源:origin: bumptech/glide

@Test
public void testSizeCallbackIsCalledSynchronouslyIfLayoutParamsConcreteSizeSet() {
 int dimens = 444;
 LayoutParams layoutParams = new LayoutParams(dimens, dimens);
 view.setLayoutParams(layoutParams);
 shadowView.setIsLaidOut(true);
 target.getSize(cb);
 verify(cb).onSizeReady(eq(dimens), eq(dimens));
}

代码示例来源:origin: bumptech/glide

@Test
public void testDecreasesDimensionsByViewPadding() {
 view.setLayoutParams(new LayoutParams(100, 100));
 view.setPadding(25, 25, 25, 25);
 shadowView.setIsLaidOut(true);
 target.getSize(cb);
 verify(cb).onSizeReady(50, 50);
}

代码示例来源:origin: bumptech/glide

@Test
public void testSizeCallbackIsCalledPreDrawIfNoDimensAndNoLayoutParamsButLayoutParamsSetLater() {
 target.getSize(cb);
 int width = 689;
 int height = 354;
 LayoutParams layoutParams = new LayoutParams(width, height);
 view.setLayoutParams(layoutParams);
 shadowView.setIsLaidOut(true);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb).onSizeReady(eq(width), eq(height));
}

代码示例来源:origin: bumptech/glide

@Test
public void testDoesNotThrowOnPreDrawIfViewTreeObserverIsDead() {
 target.getSize(cb);
 int width = 1;
 int height = 2;
 LayoutParams layoutParams = new LayoutParams(width, height);
 view.setLayoutParams(layoutParams);
 shadowView.setIsLaidOut(true);
 shadowObserver.setIsAlive(false);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb).onSizeReady(eq(width), eq(height));
}

代码示例来源:origin: bumptech/glide

@Test
public void testCallbackIsNotCalledTwiceIfPreDrawFiresTwice() {
 target.getSize(cb);
 LayoutParams layoutParams = new LayoutParams(1234, 4123);
 view.setLayoutParams(layoutParams);
 shadowView.setIsLaidOut(true);
 shadowObserver.fireOnPreDrawListeners();
 shadowObserver.fireOnPreDrawListeners();
 verify(cb, times(1)).onSizeReady(anyInt(), anyInt());
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withWidthAndHeightEqualToPadding_doesNotCallSizeReady() {
 shadowView
   .setWidth(100)
   .setHeight(100)
   .setIsLaidOut(true);
 view.setPadding(50, 50, 50, 50);
 target.getSize(cb);
 verify(cb, never()).onSizeReady(anyInt(), anyInt());
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withWrapContentHeightAndValidWidth_returnsWidthAndDisplayDimen() {
 int width = 100;
 LayoutParams params = new LayoutParams(width, LayoutParams.WRAP_CONTENT);
 view.setLayoutParams(params);
 shadowView.setIsLaidOut(true);
 setDisplayDimens(200, 100);
 target.getSize(cb);
 verify(cb).onSizeReady(width, 200);
}

代码示例来源:origin: bumptech/glide

@Test
public void testSizeCallbackIsNotCalledPreDrawIfNoDimensSetOnPreDraw() {
 target.getSize(cb);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb, never()).onSizeReady(anyInt(), anyInt());
 assertThat(shadowObserver.getPreDrawListeners()).hasSize(1);
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withLayoutParams_notLaidOut_doesCallSizeReady() {
 shadowView
   .setLayoutParams(new LayoutParams(10, 10))
   .setWidth(100)
   .setHeight(100)
   .setIsLaidOut(false);
 target.getSize(cb);
 verify(cb, times(1)).onSizeReady(anyInt(), anyInt());
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withBothWrapContent_usesDisplayDimens() {
 LayoutParams layoutParams =
   new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
 view.setLayoutParams(layoutParams);
 shadowView.setIsLaidOut(true);
 setDisplayDimens(200, 300);
 target.getSize(cb);
 verify(cb).onSizeReady(300, 300);
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withWrapContentWidthAndValidHeight_usesDisplayDimenAndValidHeight() {
 int height = 100;
 LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, height);
 view.setLayoutParams(params);
 shadowView.setIsLaidOut(true);
 setDisplayDimens(100, 200);
 target.getSize(cb);
 verify(cb).onSizeReady(200, height);
}

代码示例来源:origin: bumptech/glide

@Test
public void testMatchParentWidthAndHeight() {
 LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
 view.setLayoutParams(params);
 target.getSize(cb);
 verify(cb, never()).onSizeReady(anyInt(), anyInt());
 int width = 32;
 int height = 45;
 shadowView
   .setWidth(width)
   .setHeight(height)
   .setIsLaidOut(true);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb).onSizeReady(eq(width), eq(height));
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withMatchParentWidthAndWrapContentHeight_usesWidthAndDisplayDimenHeight() {
 LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
 view.setLayoutParams(params);
 setDisplayDimens(300, 400);
 target.getSize(cb);
 verify(cb, never()).onSizeReady(anyInt(), anyInt());
 int width = 32;
 shadowView
   .setWidth(width)
   .setIsLaidOut(true);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb).onSizeReady(width, 400);
}

代码示例来源:origin: bumptech/glide

@Test
public void testSizeCallbackIsCalledSynchronouslyIfViewSizeSet() {
 int dimens = 333;
 shadowView
   .setWidth(dimens)
   .setHeight(dimens)
   .setIsLaidOut(true);
 target.getSize(cb);
 verify(cb).onSizeReady(eq(dimens), eq(dimens));
}

代码示例来源:origin: bumptech/glide

@Test
public void testSizeCallbackIsCalledPreDrawIfNoDimensAndNoLayoutParams() {
 target.getSize(cb);
 int width = 12;
 int height = 32;
 shadowView
   .setWidth(width)
   .setHeight(height)
   .setIsLaidOut(true);
 shadowObserver.fireOnPreDrawListeners();
 verify(cb).onSizeReady(eq(width), eq(height));
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withLayoutParams_emptyParams_notLaidOutOrLayoutRequested_callsSizeReady() {
 shadowView
   .setLayoutParams(new LayoutParams(0, 0))
   .setWidth(100)
   .setHeight(100)
   .setIsLaidOut(false);
 target.getSize(cb);
 verify(cb).onSizeReady(100, 100);
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withValidWidthAndHeight_notLaidOut_notLayoutRequested_callsSizeReady() {
 shadowView
   .setWidth(100)
   .setHeight(100)
   .setIsLaidOut(false);
 target.getSize(cb);
 verify(cb).onSizeReady(100, 100);
}

代码示例来源:origin: bumptech/glide

@Test
public void getSize_withValidWidthAndHeight_preV19_layoutRequested_callsSizeReady() {
 Util.setSdkVersionInt(18);
 shadowView
   .setWidth(100)
   .setHeight(100)
   .requestLayout();
 target.getSize(cb);
 verify(cb).onSizeReady(100, 100);
}

相关文章