HorizontalHoverCardSwitcherpublic final class HorizontalHoverCardSwitcher extends PresenterSwitcher Helper class that stay bellow a HorizontalGridView and shows a hover card and align
the hover card left to left of selected child view. If there is no space when scroll
to the end, right edge hover card will be aligned to right of parent view excluding
right padding. |
Fields Summary |
---|
int | mCardLeft | int | mCardRight | private int[] | mTmpOffsets | private android.graphics.Rect | mTmpRect |
Methods Summary |
---|
protected void | insertView(android.view.View view)
// append hovercard to the end of container
getParentViewGroup().addView(view);
| protected void | onViewSelected(android.view.View view)
int rightLimit = getParentViewGroup().getWidth() -
getParentViewGroup().getPaddingRight();
int leftLimit = getParentViewGroup().getPaddingLeft();
// measure the hover card width; if it's too large, align hover card
// end edge with row view's end edge, otherwise align start edges.
view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams();
boolean isRtl = ViewCompat.getLayoutDirection(view) == View.LAYOUT_DIRECTION_RTL;
if (!isRtl && mCardLeft + view.getMeasuredWidth() > rightLimit) {
params.leftMargin = rightLimit - view.getMeasuredWidth();
} else if (isRtl && mCardLeft < leftLimit) {
params.leftMargin = leftLimit;
} else if (isRtl) {
params.leftMargin = mCardRight - view.getMeasuredWidth();
} else {
params.leftMargin = mCardLeft;
}
view.requestLayout();
| public void | select(HorizontalGridView gridView, android.view.View childView, java.lang.Object object)Select a childView inside a grid view and create/bind a corresponding hover card view
for the object.
ViewGroup parent = getParentViewGroup();
gridView.getViewSelectedOffsets(childView, mTmpOffsets);
mTmpRect.set(0, 0, childView.getWidth(), childView.getHeight());
parent.offsetDescendantRectToMyCoords(childView, mTmpRect);
mCardLeft = mTmpRect.left - mTmpOffsets[0];
mCardRight = mTmpRect.right - mTmpOffsets[0];
select(object);
|
|