Search in sources :

Example 11 with CoordinatorLayout

use of android.support.design.widget.CoordinatorLayout in project XRecyclerView by jianghejie.

the class XRecyclerView method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    // 解决和CollapsingToolbarLayout冲突的问题
    AppBarLayout appBarLayout = null;
    ViewParent p = getParent();
    while (p != null) {
        if (p instanceof CoordinatorLayout) {
            break;
        }
        p = p.getParent();
    }
    if (p instanceof CoordinatorLayout) {
        CoordinatorLayout coordinatorLayout = (CoordinatorLayout) p;
        final int childCount = coordinatorLayout.getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            final View child = coordinatorLayout.getChildAt(i);
            if (child instanceof AppBarLayout) {
                appBarLayout = (AppBarLayout) child;
                break;
            }
        }
        if (appBarLayout != null) {
            appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {

                @Override
                public void onStateChanged(AppBarLayout appBarLayout, State state) {
                    appbarState = state;
                }
            });
        }
    }
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ViewParent(android.view.ViewParent) AppBarLayout(android.support.design.widget.AppBarLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 12 with CoordinatorLayout

use of android.support.design.widget.CoordinatorLayout in project StatusBarUtil by laobie.

the class StatusBarUtil method setColorForSwipeBack.

/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {

                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 13 with CoordinatorLayout

use of android.support.design.widget.CoordinatorLayout in project ListenerMusicPlayer by hefuyicoder.

the class RotationFabBehavior method offsetIfNeeded.

/**
     * Pre-Lollipop we use padding so that the shadow has enough space to be drawn. This method
     * offsets our layout position so that we're positioned correctly if we're on one of
     * our parent's edges.
     */
private void offsetIfNeeded(CoordinatorLayout parent, FloatingActionButton fab) {
    Rect padding = new Rect(0, 0, 0, 0);
    try {
        Field mShadowPadding = FloatingActionButton.class.getDeclaredField("mShadowPadding");
        mShadowPadding.setAccessible(true);
        padding = (Rect) mShadowPadding.get(fab);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    if (padding != null && padding.centerX() > 0 && padding.centerY() > 0) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
        int offsetTB = 0, offsetLR = 0;
        if (fab.getRight() >= parent.getWidth() - lp.rightMargin) {
            // If we're on the right edge, shift it the right
            offsetLR = padding.right;
        } else if (fab.getLeft() <= lp.leftMargin) {
            // If we're on the left edge, shift it the left
            offsetLR = -padding.left;
        }
        if (fab.getBottom() >= parent.getHeight() - lp.bottomMargin) {
            // If we're on the bottom edge, shift it down
            offsetTB = padding.bottom;
        } else if (fab.getTop() <= lp.topMargin) {
            // If we're on the top edge, shift it up
            offsetTB = -padding.top;
        }
        if (offsetTB != 0) {
            ViewCompat.offsetTopAndBottom(fab, offsetTB);
        }
        if (offsetLR != 0) {
            ViewCompat.offsetLeftAndRight(fab, offsetLR);
        }
    }
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Field(java.lang.reflect.Field) Rect(android.graphics.Rect)

Example 14 with CoordinatorLayout

use of android.support.design.widget.CoordinatorLayout in project smooth-app-bar-layout by henrytao-me.

the class BaseBehavior method getSupportedScrollTarget.

private View getSupportedScrollTarget(View target) {
    if (target instanceof SwipeRefreshLayout && ((SwipeRefreshLayout) target).getChildCount() > 0) {
        SwipeRefreshLayout parent = (SwipeRefreshLayout) target;
        View child;
        int n = parent.getChildCount();
        for (int i = 0; i < n; i++) {
            child = parent.getChildAt(i);
            if (child instanceof NestedScrollView || child instanceof RecyclerView) {
                return child;
            }
        }
        return ((SwipeRefreshLayout) target).getChildAt(0);
    } else if (target instanceof CoordinatorLayout) {
        Stack<View> stack = new Stack<>();
        stack.add(target);
        while (stack.size() > 0) {
            View view = stack.pop();
            if (view instanceof NestedScrollView || view instanceof RecyclerView) {
                return view;
            }
            if (view instanceof ViewGroup) {
                int n = ((ViewGroup) view).getChildCount();
                for (int i = 0; i < n; i++) {
                    stack.add(((ViewGroup) view).getChildAt(i));
                }
            }
        }
    }
    return target;
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ViewGroup(android.view.ViewGroup) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) Stack(java.util.Stack)

Example 15 with CoordinatorLayout

use of android.support.design.widget.CoordinatorLayout in project BottomBar by roughike.

the class BottomBar method initializeShyBehavior.

private void initializeShyBehavior() {
    ViewParent parent = getParent();
    boolean hasAbusiveParent = parent != null && parent instanceof CoordinatorLayout;
    if (!hasAbusiveParent) {
        throw new RuntimeException("In order to have shy behavior, the " + "BottomBar must be a direct child of a CoordinatorLayout.");
    }
    if (!shyHeightAlreadyCalculated) {
        int height = getHeight();
        if (height != 0) {
            updateShyHeight(height);
            shyHeightAlreadyCalculated = true;
        }
    }
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ViewParent(android.view.ViewParent)

Aggregations

CoordinatorLayout (android.support.design.widget.CoordinatorLayout)21 View (android.view.View)16 AppBarLayout (android.support.design.widget.AppBarLayout)9 RecyclerView (android.support.v7.widget.RecyclerView)7 ViewGroup (android.view.ViewGroup)7 TextView (android.widget.TextView)6 PagerAdapter (android.support.v4.view.PagerAdapter)4 ViewPager (android.support.v4.view.ViewPager)4 NestedScrollView (android.support.v4.widget.NestedScrollView)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ViewParent (android.view.ViewParent)4 ImageView (android.widget.ImageView)4 TabLayout (android.support.design.widget.TabLayout)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)3 Toolbar (android.support.v7.widget.Toolbar)3 ContextThemeWrapper (android.view.ContextThemeWrapper)3 Menu (android.view.Menu)3 MenuItem (android.view.MenuItem)3 ViewTreeObserver (android.view.ViewTreeObserver)3 Activity (android.app.Activity)2