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;
}
});
}
}
}
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);
}
}
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);
}
}
}
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;
}
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;
}
}
}
Aggregations