本文整理了Java中android.widget.ImageView.getViewTreeObserver()
方法的一些代码示例,展示了ImageView.getViewTreeObserver()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageView.getViewTreeObserver()
方法的具体详情如下:
包路径:android.widget.ImageView
类名称:ImageView
方法名:getViewTreeObserver
暂无
代码示例来源:origin: stackoverflow.com
int finalHeight, finalWidth;
final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
final TextView tv = (TextView)findViewById(R.id.size_label);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
iv.getViewTreeObserver().removeOnPreDrawListener(this);
finalHeight = iv.getMeasuredHeight();
finalWidth = iv.getMeasuredWidth();
tv.setText("Height: " + finalHeight + " Width: " + finalWidth);
return true;
}
});
代码示例来源:origin: jaydenxiao2016/AndroidFire
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
iv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
iv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) iv.getLayoutParams();
params.height = params.width;
iv.setLayoutParams(params);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
});
代码示例来源:origin: frogermcs/InstaMaterial
@Override
public boolean onPreDraw() {
ivPhoto.getViewTreeObserver().removeOnPreDrawListener(this);
loadThumbnailPhoto();
return true;
}
});
代码示例来源:origin: jiangqqlmj/FastDev4Android
/**
* Clean-up the resources attached to this object. This needs to be called
* when the ImageView is no longer used. A good example is from
* {@link View#onDetachedFromWindow()} or from
* {@link android.app.Activity#onDestroy()}. This is automatically called if
* you are using {@link uk.co.senab.photoview.PhotoView}.
*/
@SuppressWarnings("deprecation")
public final void cleanup() {
if (null != mImageView) {
mImageView.get().getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
mViewTreeObserver = null;
// Clear listeners too
mMatrixChangeListener = null;
mPhotoTapListener = null;
mViewTapListener = null;
// Finally, clear ImageView
mImageView = null;
}
代码示例来源:origin: florent37/CameraFragment
public void into(final ImageView target) {
ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
target.getViewTreeObserver().removeOnPreDrawListener(this);
new ImageLoaderThread(target, url).start();
return true;
}
});
}
代码示例来源:origin: stackoverflow.com
int finalHeight, finalWidth;
final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
final TextView tv = (TextView)findViewById(R.id.size_label);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
// Remove after the first run so it doesn't fire forever
iv.getViewTreeObserver().removeOnPreDrawListener(this);
finalHeight = iv.getMeasuredHeight();
finalWidth = iv.getMeasuredWidth();
tv.setText("Height: " + finalHeight + " Width: " + finalWidth);
return true;
}
});
代码示例来源:origin: wangdan/AisenWeiBo
public PhotoViewAttacher(ImageView imageView) {
mImageView = new WeakReference<ImageView>(imageView);
mViewTreeObserver = imageView.getViewTreeObserver();
mViewTreeObserver.addOnGlobalLayoutListener(this);
// Make sure we using MATRIX Scale Type
setImageViewScaleTypeMatrix(imageView);
if (!imageView.isInEditMode()) {
setZoomable(true);
}
}
代码示例来源:origin: square/picasso
static ImageView mockFitImageViewTarget(boolean alive) {
ViewTreeObserver observer = mock(ViewTreeObserver.class);
when(observer.isAlive()).thenReturn(alive);
ImageView mock = mock(ImageView.class);
when(mock.getWindowToken()).thenReturn(mock(IBinder.class));
when(mock.getViewTreeObserver()).thenReturn(observer);
return mock;
}
代码示例来源:origin: square/picasso
void cancel() {
creator.clearTag();
callback = null;
target.removeOnAttachStateChangeListener(this);
ViewTreeObserver vto = target.getViewTreeObserver();
if (vto.isAlive()) {
vto.removeOnPreDrawListener(this);
}
}
代码示例来源:origin: square/picasso
@Override public boolean onPreDraw() {
ImageView target = this.target;
ViewTreeObserver vto = target.getViewTreeObserver();
if (!vto.isAlive()) {
return true;
}
int width = target.getWidth();
int height = target.getHeight();
if (width <= 0 || height <= 0) {
return true;
}
target.removeOnAttachStateChangeListener(this);
vto.removeOnPreDrawListener(this);
this.creator.unfit().resize(width, height).into(target, callback);
return true;
}
代码示例来源:origin: square/picasso
@Test public void waitsForAnotherLayoutIfWidthOrHeightIsZero() {
ImageView target = mockFitImageViewTarget(true);
when(target.getWidth()).thenReturn(0);
when(target.getHeight()).thenReturn(0);
RequestCreator creator = mock(RequestCreator.class);
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
request.onPreDraw();
verify(target.getViewTreeObserver(), never()).removeOnPreDrawListener(request);
verifyZeroInteractions(creator);
}
代码示例来源:origin: florent37/CameraFragment
public boolean onPreDraw() {
target.getViewTreeObserver().removeOnPreDrawListener(this);
new ImageLoaderThread(target, url).start();
return true;
}
});
代码示例来源:origin: wangdan/AisenWeiBo
@Override
public boolean onPreDraw() {
img.getViewTreeObserver().removeOnPreDrawListener(this);
width = img.getWidth();
ActivityHelper.putIntShareData(GlobalContext.getInstance(), "WallpaperWidth", width);
onBindData(convertView, data, position);
return true;
}
代码示例来源:origin: square/picasso
@Test public void onLayoutSkipsIfViewIsAttachedAndViewTreeObserverIsDead() {
ImageView target = mockFitImageViewTarget(false);
RequestCreator creator = mock(RequestCreator.class);
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
ViewTreeObserver viewTreeObserver = target.getViewTreeObserver();
request.onPreDraw();
verify(viewTreeObserver).addOnPreDrawListener(request);
verify(viewTreeObserver).isAlive();
verifyNoMoreInteractions(viewTreeObserver);
verifyZeroInteractions(creator);
}
代码示例来源:origin: frogermcs/InstaMaterial
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_publish);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_grey600_24dp);
photoSize = getResources().getDimensionPixelSize(R.dimen.publish_photo_thumbnail_size);
if (savedInstanceState == null) {
photoUri = getIntent().getParcelableExtra(ARG_TAKEN_PHOTO_URI);
} else {
photoUri = savedInstanceState.getParcelable(ARG_TAKEN_PHOTO_URI);
}
updateStatusBarColor();
ivPhoto.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
ivPhoto.getViewTreeObserver().removeOnPreDrawListener(this);
loadThumbnailPhoto();
return true;
}
});
}
代码示例来源:origin: square/picasso
@Test public void initWhileAttachedAddsAttachAndPreDrawListener() {
ImageView target = mockFitImageViewTarget(true);
ViewTreeObserver observer = target.getViewTreeObserver();
DeferredRequestCreator request =
new DeferredRequestCreator(mock(RequestCreator.class), target, null);
verify(observer).addOnPreDrawListener(request);
}
代码示例来源:origin: square/picasso
@Test public void cancelSkipsIfViewTreeObserverIsDead() {
ImageView target = mockFitImageViewTarget(false);
RequestCreator creator = mock(RequestCreator.class);
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
request.cancel();
verify(target.getViewTreeObserver(), never()).removeOnPreDrawListener(request);
}
代码示例来源:origin: square/picasso
@Test public void preDrawSubmitsRequestAndCleansUp() {
Picasso picasso = mock(Picasso.class);
when(picasso.transformRequest(any(Request.class))).thenAnswer(TRANSFORM_REQUEST_ANSWER);
RequestCreator creator = new RequestCreator(picasso, URI_1, 0);
ImageView target = mockFitImageViewTarget(true);
when(target.getWidth()).thenReturn(100);
when(target.getHeight()).thenReturn(100);
ViewTreeObserver observer = target.getViewTreeObserver();
DeferredRequestCreator request = new DeferredRequestCreator(creator, target, null);
request.onPreDraw();
verify(observer).removeOnPreDrawListener(request);
verify(picasso).enqueueAndSubmit(actionCaptor.capture());
Action value = actionCaptor.getValue();
assertThat(value).isInstanceOf(ImageViewAction.class);
assertThat(value.request.targetWidth).isEqualTo(100);
assertThat(value.request.targetHeight).isEqualTo(100);
}
}
代码示例来源:origin: square/picasso
@Test public void initWhileDetachedAddsAttachListenerWhichDefersPreDrawListener() {
ImageView target = mockFitImageViewTarget(true);
when(target.getWindowToken()).thenReturn(null);
ViewTreeObserver observer = target.getViewTreeObserver();
DeferredRequestCreator request =
new DeferredRequestCreator(mock(RequestCreator.class), target, null);
verify(target).addOnAttachStateChangeListener(request);
verifyNoMoreInteractions(observer);
// Attach and ensure we defer to the pre-draw listener.
request.onViewAttachedToWindow(target);
verify(observer).addOnPreDrawListener(request);
// Detach and ensure we remove the pre-draw listener from the original VTO.
request.onViewDetachedFromWindow(target);
verify(observer).removeOnPreDrawListener(request);
}
代码示例来源:origin: alexvasilkov/GestureViews
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_cross_animation_from_screen);
getSupportActionBarNotNull().setDisplayHomeAsUpEnabled(true);
image = findViewById(R.id.single_image_from);
// Loading image
Painting painting = Painting.list(getResources())[PAINTING_ID];
GlideHelper.loadThumb(image, painting.thumbId);
// Setting image click listener
image.setOnClickListener(this::showFullImage);
// Image position may change (e.g. when screen orientation is changed), so we should update
// fullscreen image to ensure exit animation will return image into correct position.
image.getViewTreeObserver().addOnGlobalLayoutListener(this::onLayoutChanges);
}
内容来源于网络,如有侵权,请联系作者删除!