本文整理汇总了Java中android.view.ViewTreeObserver.addOnPreDrawListener方法的典型用法代码示例。如果您正苦于以下问题:Java ViewTreeObserver.addOnPreDrawListener方法的具体用法?Java ViewTreeObserver.addOnPreDrawListener怎么用?Java ViewTreeObserver.addOnPreDrawListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.ViewTreeObserver
的用法示例。
在下文中一共展示了ViewTreeObserver.addOnPreDrawListener方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSize
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
void getSize(SizeReadyCallback cb) {
int currentWidth = getTargetWidth();
int currentHeight = getTargetHeight();
if (isViewStateAndSizeValid(currentWidth, currentHeight)) {
cb.onSizeReady(currentWidth, currentHeight);
return;
}
// We want to notify callbacks in the order they were added and we only expect one or two
// callbacks to be added a time, so a List is a reasonable choice.
if (!cbs.contains(cb)) {
cbs.add(cb);
}
if (layoutListener == null) {
ViewTreeObserver observer = view.getViewTreeObserver();
layoutListener = new SizeDeterminerLayoutListener(this);
observer.addOnPreDrawListener(layoutListener);
}
}
示例2: preDraw
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
/**
* Runs a runnable when the view tree is about to be drawn.At this point, all views in the tree
* have been measured and given a frame.
*
* @param runnable The Runnable to run.
*
* @return The current AQuery object
*
* @throws IllegalArgumentException If the runnable passed in null
*/
@NonNull
public AQ preDraw(@NonNull final Runnable runnable) {
requireNotNull(runnable);
final ViewTreeObserver treeObserver = raw().getViewTreeObserver();
treeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
treeObserver.removeOnPreDrawListener(this);
runnable.run();
return true;
}
});
return this;
}
示例3: init
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
private void init() {
ViewTreeObserver observer = getViewTreeObserver();
if (observer != null) {
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (isDirty()) {
// 只在需要绘制的时候刷新
if (mRenderMode == GLSurfaceView.RENDERMODE_WHEN_DIRTY) {
invalidate();
}
}
return true;
}
});
}
}
示例4: onLayout
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
ViewTreeObserver observer = getViewTreeObserver();
if (getVisibility() == View.VISIBLE && changed && observer != null && observer.isAlive()) {
observer.addOnPreDrawListener(mPredrawListener);
}
}
示例5: setImageBitmap
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
@Override
public void setImageBitmap(Bitmap bm) {
// TODO Auto-generated method stub
super.setImageBitmap(bm);
//大小为0 表示当前控件大小未测量 设置监听函数 在绘制前赋值
if(getWidth()==0){
ViewTreeObserver vto = getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
{
public boolean onPreDraw()
{
initData();
//赋值结束后,移除该监听函数
MatrixImageView.this.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
});
}else {
initData();
}
}
示例6: fixLayout
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
private void fixLayout() {
if (listView != null) {
ViewTreeObserver obs = listView.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
fixLayoutInternal();
if (listView != null) {
listView.getViewTreeObserver().removeOnPreDrawListener(this);
}
return true;
}
});
}
}
示例7: onConfigurationChanged
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (listView != null) {
ViewTreeObserver obs = listView.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
listView.getViewTreeObserver().removeOnPreDrawListener(this);
fixLayoutInternal();
return true;
}
});
}
}
示例8: toggle
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
private void toggle(final boolean visible, final boolean animate, boolean force) {
if (mVisible != visible || force) {
mVisible = visible;
int height = getHeight();
if (height == 0 && !force) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
ViewTreeObserver currentVto = getViewTreeObserver();
if (currentVto.isAlive()) {
currentVto.removeOnPreDrawListener(this);
}
toggle(visible, animate, true);
return true;
}
});
return;
}
}
int translationY = visible ? 0 : height + getMarginBottom();
if (animate) {
animate().setInterpolator(mInterpolator)
.setDuration(TRANSLATE_DURATION_MILLIS)
.translationY(translationY);
} else {
setTranslationY(translationY);
}
// On pre-Honeycomb a translated view is still clickable, so we need to disable clicks manually
if (!Utils.hasHoneycomb()) {
setClickable(visible);
}
}
if(isMenuOpen()) {
closeMenu();
}
}
示例9: addPreDrawListener
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
/**
* Add the pre-draw listener if we're attached to a window and mark that we currently
* need it when attached.
*/
void addPreDrawListener() {
if (mIsAttachedToWindow) {
// Add the listener
if (mOnPreDrawListener == null) {
mOnPreDrawListener = new OnPreDrawListener();
}
final ViewTreeObserver vto = getViewTreeObserver();
vto.addOnPreDrawListener(mOnPreDrawListener);
}
// Record that we need the listener regardless of whether or not we're attached.
// We'll add the real listener when we become attached.
mNeedsPreDrawListener = true;
}
示例10: toggle
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
private void toggle(final boolean visible, final boolean animate, boolean force) {
if (mVisible != visible || force) {
mVisible = visible;
int height = getHeight();
if (height == 0 && !force) {
ViewTreeObserver vto = getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
ViewTreeObserver currentVto = getViewTreeObserver();
if (currentVto.isAlive()) {
currentVto.removeOnPreDrawListener(this);
}
toggle(visible, animate, true);
return true;
}
});
return;
}
}
int translationY = visible ? 0 : height + getMarginBottom();
if (animate) {
animate().setInterpolator(mInterpolator)
.setDuration(TRANSLATE_DURATION_MILLIS)
.translationY(translationY);
} else {
setTranslationY(translationY);
}
// On pre-Honeycomb a translated view is still clickable, so we need to disable clicks manually
if (!Utils.hasHoneycomb()) {
setClickable(visible);
}
}
}
示例11: setText
import android.view.ViewTreeObserver; //导入方法依赖的package包/类
public void setText(CharSequence charSequence) {
textContent = charSequence;
textView.setText(charSequence.toString());
ViewTreeObserver viewTreeObserver = textView.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!isInitTextView) {
return true;
}
textLines = textView.getLineCount();
isExpandNeeded = textLines > expandLines;
isInitTextView = false;
if (isExpandNeeded) {
isShrink = true;
doAnimation(textLines, expandLines, WHAT_ANIMATION_END);
} else {
isShrink = false;
doNotExpand();
}
return true;
}
});
if (!isInitTextView) {
textLines = textView.getLineCount();
}
}