List of usage examples for android.view View isInLayout
public boolean isInLayout()
From source file:com.jecelyin.editor.v2.core.view.ViewCompat.java
public static boolean isInLayout(View view) { if (Build.VERSION.SDK_INT >= 18) return view.isInLayout(); return false; }
From source file:com.muller.snappingsample.SnappingRecyclerView.java
/** * Adds the margins to a childView so a view will still center even if it's only a single child * @param child childView to set margins for *///from ww w. j a v a2s. com private void setMarginsForChild(View child) { int lastItemIndex = getLayoutManager().getItemCount() - 1; int childIndex = getChildAdapterPosition(child); int startMargin = 0; int endMargin = 0; int topMargin = 0; int bottomMargin = 0; if (_orientation == Orientation.VERTICAL) { topMargin = childIndex == 0 ? getCenterLocation() : 0; bottomMargin = childIndex == lastItemIndex ? getCenterLocation() : 0; } else { startMargin = childIndex == 0 ? getCenterLocation() : 0; endMargin = childIndex == lastItemIndex ? getCenterLocation() : 0; } /** if sdk minimum level is 17, set RTL margins **/ if (_orientation == Orientation.HORIZONTAL && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { ((MarginLayoutParams) child.getLayoutParams()).setMarginStart(startMargin); ((MarginLayoutParams) child.getLayoutParams()).setMarginEnd(endMargin); } /** If layout direction is RTL, swap the margins **/ if (ViewCompat.getLayoutDirection(child) == ViewCompat.LAYOUT_DIRECTION_RTL) { ((MarginLayoutParams) child.getLayoutParams()).setMargins(endMargin, topMargin, startMargin, bottomMargin); } else { ((MarginLayoutParams) child.getLayoutParams()).setMargins(startMargin, topMargin, endMargin, bottomMargin); } /** if sdk minimum level is 18, check if view isn't undergoing a layout pass (this improves the feel of the view by a lot) **/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (!child.isInLayout()) child.requestLayout(); } }