当前位置: 首页>>代码示例>>Java>>正文


Java ViewTreeObserver.addOnPreDrawListener方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:ViewTarget.java

示例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;
}
 
开发者ID:mzaart,项目名称:AQuery,代码行数:26,代码来源:AQ.java

示例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;
            }
        });
    }
}
 
开发者ID:uestccokey,项目名称:EZFilter,代码行数:18,代码来源:GLLinearLayout.java

示例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);
    }
}
 
开发者ID:StylingAndroid,项目名称:PresenterLite,代码行数:9,代码来源:GraphicalLayout.java

示例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();
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:22,代码来源:MatrixImageView.java

示例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;
            }
        });
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:16,代码来源:PhotoAlbumPickerActivity.java

示例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;
            }
        });
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:16,代码来源:MediaActivity.java

示例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();
    }
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:40,代码来源:FloatingActionsMenu.java

示例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;
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:19,代码来源:CoordinatorLayout.java

示例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);
        }
    }

}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:37,代码来源:FloatingActionButton.java

示例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();
        }

    }
 
开发者ID:zhao-mingjian,项目名称:qvod,代码行数:34,代码来源:TextViewExpandableAnimation.java


注:本文中的android.view.ViewTreeObserver.addOnPreDrawListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。