當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。