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