當前位置: 首頁>>代碼示例>>Java>>正文


Java GravityCompat.apply方法代碼示例

本文整理匯總了Java中android.support.v4.view.GravityCompat.apply方法的典型用法代碼示例。如果您正苦於以下問題:Java GravityCompat.apply方法的具體用法?Java GravityCompat.apply怎麽用?Java GravityCompat.apply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.view.GravityCompat的用法示例。


在下文中一共展示了GravityCompat.apply方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
開發者ID:zuoni1018,項目名稱:CoordinatorLayoutExample-master,代碼行數:26,代碼來源:HeaderScrollingViewBehavior.java

示例2: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
protected void layoutChild(CoordinatorLayout parent, View child, int layoutDirection) {
    View header = findFirstDependency(parent.getDependencies(child));
    if (header != null) {
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        Rect available = this.mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin, (parent.getWidth() - parent.getPaddingRight()) - lp.rightMargin, ((parent.getHeight() + header.getBottom()) - parent.getPaddingBottom()) - lp.bottomMargin);
        Rect out = this.mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);
        int overlap = getOverlapPixelsForOffset(header);
        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        this.mVerticalLayoutGap = out.top - header.getBottom();
        return;
    }
    super.layoutChild(parent, child, layoutDirection);
    this.mVerticalLayoutGap = 0;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:HeaderScrollingViewBehavior.java

示例3: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child,
                           final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp =
                (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin,
                header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom()
                        - parent.getPaddingBottom() - lp.bottomMargin);

        /*final WindowInsetsCompat parentInsets = parent.getLastWindowInsets();
        if (parentInsets != null && ViewCompat.getFitsSystemWindows(parent)
                && !ViewCompat.getFitsSystemWindows(child)) {
            // If we're set to handle insets but this child isn't, then it has been measured as
            // if there are no insets. We need to lay it out to match horizontally.
            // Top and bottom and already handled in the logic above
            available.left += parentInsets.getSystemWindowInsetLeft();
            available.right -= parentInsets.getSystemWindowInsetRight();
        }*/

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(),
                child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
開發者ID:huyongli,項目名稱:UCMainViewForBehavior,代碼行數:41,代碼來源:HeaderScrollingViewBehavior.java

示例4: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
@Override
  protected void layoutChild(final CoordinatorLayout parent, final View child,
          final int layoutDirection) {
  final List<View> dependencies = parent.getDependencies(child);
  final View header = findFirstDependency(dependencies);

  if (header != null) {
    final CoordinatorLayout.LayoutParams lp =
        (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    final Rect available = mTempRect1;
          available.set(parent.getPaddingLeft() + lp.leftMargin,
        header.getBottom() + lp.topMargin,
        parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                  parent.getHeight() + header.getBottom()
                          - parent.getPaddingBottom() - lp.bottomMargin);

    final WindowInsetsCompat parentInsets = parent.getLastWindowInsets();
          if (parentInsets != null && ViewCompat.getFitsSystemWindows(parent)
        && !ViewCompat.getFitsSystemWindows(child)) {
      // If we're set to handle insets but this child isn't, then it has been measured as
      // if there are no insets. We need to lay it out to match horizontally.
      // Top and bottom and already handled in the logic above
      available.left += parentInsets.getSystemWindowInsetLeft();
      available.right -= parentInsets.getSystemWindowInsetRight();
    }

    final Rect out = mTempRect2;
          GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(),
                  child.getMeasuredHeight(), available, out, layoutDirection);

    final int overlap = getOverlapPixelsForOffset(header);

    child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
    mVerticalLayoutGap = out.top - header.getBottom();
  } else {
    // If we don't have a dependency, let super handle it
    super.layoutChild(parent, child, layoutDirection);
    mVerticalLayoutGap = 0;
  }
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:41,代碼來源:HeaderScrollingViewBehavior.java

示例5: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
/**
   * Lay out a child view with no special handling. This will position the child as
   * if it were within a FrameLayout or similar simple frame.
 *
 * @param child child view to lay out
 * @param layoutDirection ViewCompat constant for the desired layout direction
 */
private void layoutChild(View child, int layoutDirection) {
  final LayoutParams lp = (LayoutParams) child.getLayoutParams();
  final Rect parent = acquireTempRect();
      parent.set(getPaddingLeft() + lp.leftMargin,
      getPaddingTop() + lp.topMargin,
      getWidth() - getPaddingRight() - lp.rightMargin,
      getHeight() - getPaddingBottom() - lp.bottomMargin);

      if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this)
      && !ViewCompat.getFitsSystemWindows(child)) {
    // If we're set to handle insets but this child isn't, then it has been measured as
    // if there are no insets. We need to lay it out to match.
    parent.left += mLastInsets.getSystemWindowInsetLeft();
    parent.top += mLastInsets.getSystemWindowInsetTop();
    parent.right -= mLastInsets.getSystemWindowInsetRight();
    parent.bottom -= mLastInsets.getSystemWindowInsetBottom();
  }

  final Rect out = acquireTempRect();
      GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(),
              child.getMeasuredHeight(), parent, out, layoutDirection);
  child.layout(out.left, out.top, out.right, out.bottom);

  releaseTempRect(parent);
  releaseTempRect(out);
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:34,代碼來源:CoordinatorLayout.java

示例6: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
private void layoutChild(View child, int layoutDirection) {
    LayoutParams lp = (LayoutParams) child.getLayoutParams();
    Rect parent = this.mTempRect1;
    parent.set(getPaddingLeft() + lp.leftMargin, getPaddingTop() + lp.topMargin, (getWidth() - getPaddingRight()) - lp.rightMargin, (getHeight() - getPaddingBottom()) - lp.bottomMargin);
    if (!(this.mLastInsets == null || !ViewCompat.getFitsSystemWindows(this) || ViewCompat.getFitsSystemWindows(child))) {
        parent.left += this.mLastInsets.getSystemWindowInsetLeft();
        parent.top += this.mLastInsets.getSystemWindowInsetTop();
        parent.right -= this.mLastInsets.getSystemWindowInsetRight();
        parent.bottom -= this.mLastInsets.getSystemWindowInsetBottom();
    }
    Rect out = this.mTempRect2;
    GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), parent, out, layoutDirection);
    child.layout(out.left, out.top, out.right, out.bottom);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:15,代碼來源:CoordinatorLayout.java

示例7: gravityCompatApply

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
void gravityCompatApply(int gravity, int bitmapWidth, int bitmapHeight, Rect bounds, Rect outRect) {
    GravityCompat.apply(gravity, bitmapWidth, bitmapHeight, bounds, outRect, 0);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:4,代碼來源:RoundedBitmapDrawableFactory.java

示例8: layoutChild

import android.support.v4.view.GravityCompat; //導入方法依賴的package包/類
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child,
                           final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp =
                (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin,
                header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom()
                        - parent.getPaddingBottom() - lp.bottomMargin);

        //修改代碼,通過反射執行getLastWindowInsets()方法
        try {
            Method method = parent.getClass().getDeclaredMethod("getLastWindowInsets", (Class<?>[]) new Object[]{});
            method.setAccessible(true);
            final WindowInsetsCompat parentInsets = (WindowInsetsCompat) method.invoke(parent);
            if (parentInsets != null && ViewCompat.getFitsSystemWindows(parent)
                    && !ViewCompat.getFitsSystemWindows(child)) {
                // If we're set to handle insets but this child isn't, then it has been measured as
                // if there are no insets. We need to lay it out to match horizontally.
                // Top and bottom and already handled in the logic above
                available.left += parentInsets.getSystemWindowInsetLeft();
                available.right -= parentInsets.getSystemWindowInsetRight();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(),
                child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
開發者ID:Othershe,項目名稱:BehaviorDemo,代碼行數:48,代碼來源:HeaderScrollingViewBehavior.java


注:本文中的android.support.v4.view.GravityCompat.apply方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。