本文整理匯總了Java中android.view.ViewTreeObserver.addOnDrawListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewTreeObserver.addOnDrawListener方法的具體用法?Java ViewTreeObserver.addOnDrawListener怎麽用?Java ViewTreeObserver.addOnDrawListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.ViewTreeObserver
的用法示例。
在下文中一共展示了ViewTreeObserver.addOnDrawListener方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
view = (CustomView) findViewById(R.id.view);
ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
viewTreeObserver.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
@Override
public void onDraw() {
}
});
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
}
});
}
示例2: onWindowVisibilityChanged
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public void onWindowVisibilityChanged(int visibility) {
// The following code used to be in onResume, but it turns out onResume is called when
// you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
// is a more appropriate event to handle
if (visibility == View.VISIBLE) {
if (!mWorkspaceLoading) {
final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
// We want to let Launcher draw itself at least once before we force it to build
// layers on all the workspace pages, so that transitioning to Launcher from other
// apps is nice and speedy.
observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
private boolean mStarted = false;
public void onDraw() {
if (mStarted) return;
mStarted = true;
// We delay the layer building a bit in order to give
// other message processing a time to run. In particular
// this avoids a delay in hiding the IME if it was
// currently shown, because doing that may involve
// some communication back with the app.
mWorkspace.postDelayed(mBuildLayersRunnable, 500);
final ViewTreeObserver.OnDrawListener listener = this;
mWorkspace.post(new Runnable() {
public void run() {
if (mWorkspace != null &&
mWorkspace.getViewTreeObserver() != null) {
mWorkspace.getViewTreeObserver().
removeOnDrawListener(listener);
}
}
});
return;
}
});
}
clearTypedText();
}
}
示例3: onWindowVisibilityChanged
import android.view.ViewTreeObserver; //導入方法依賴的package包/類
public void onWindowVisibilityChanged(int visibility) {
mVisible = visibility == View.VISIBLE;
updateAutoAdvanceState();
// The following code used to be in onResume, but it turns out onResume is called when
// you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
// is a more appropriate event to handle
if (mVisible) {
if (!mWorkspaceLoading) {
final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
// We want to let Launcher draw itself at least once before we force it to build
// layers on all the workspace pages, so that transitioning to Launcher from other
// apps is nice and speedy.
observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
private boolean mStarted = false;
public void onDraw() {
if (mStarted) return;
mStarted = true;
// We delay the layer building a bit in order to give
// other message processing a time to run. In particular
// this avoids a delay in hiding the IME if it was
// currently shown, because doing that may involve
// some communication back with the app.
mWorkspace.postDelayed(mBuildLayersRunnable, 500);
final ViewTreeObserver.OnDrawListener listener = this;
mWorkspace.post(new Runnable() {
public void run() {
if (mWorkspace != null &&
mWorkspace.getViewTreeObserver() != null) {
mWorkspace.getViewTreeObserver().
removeOnDrawListener(listener);
}
}
});
return;
}
});
}
clearTypedText();
}
}