本文整理匯總了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();
}
}