下面列出了androidx.recyclerview.widget.RecyclerView#getMeasuredHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void drawVertical(Canvas canvas, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
final int childSize = parent.getChildCount();
for (int i = 0; i < childSize; i++) {
final View child = parent.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
final int left = child.getRight() + layoutParams.rightMargin;
final int right = left + space;
if (mDivider != null) {
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(canvas);
}
if (mPaint != null) {
canvas.drawRect(left, top, right, bottom, mPaint);
}
}
}
private void drawVertical(Canvas canvas, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom();
final int childSize = parent.getChildCount();
for (int i = 0; i < childSize; i++) {
final View child = parent.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
final int left = child.getRight() + layoutParams.rightMargin;
final int right = left + space;
if (mDivider != null) {
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(canvas);
}
if (mPaint != null) {
canvas.drawRect(left, top, right, bottom, mPaint);
}
}
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
boolean adapterIsEmpty = rv.getAdapter() == null || rv.getAdapter().getItemCount() == 0;
boolean result = dragSelectActive && !adapterIsEmpty;
if (result) {
recyclerView = rv;
if (hotspotHeight > -1) {
hotspotTopBoundStart = hotspotOffsetTop;
hotspotTopBoundEnd = hotspotOffsetTop + hotspotHeight;
hotspotBottomBoundStart = rv.getMeasuredHeight() - hotspotHeight - hotspotOffsetBottom;
hotspotBottomBoundEnd = rv.getMeasuredHeight() - hotspotOffsetBottom;
}
}
if (result && e.getAction() == MotionEvent.ACTION_UP) {
onDragSelectionStop();
}
return result;
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
boolean adapterIsEmpty = rv.getAdapter() == null || rv.getAdapter().getItemCount() == 0;
boolean result = dragSelectActive && !adapterIsEmpty;
if (result) {
recyclerView = rv;
if (hotspotHeight > -1) {
hotspotTopBoundStart = hotspotOffsetTop;
hotspotTopBoundEnd = hotspotOffsetTop + hotspotHeight;
hotspotBottomBoundStart = rv.getMeasuredHeight() - hotspotHeight - hotspotOffsetBottom;
hotspotBottomBoundEnd = rv.getMeasuredHeight() - hotspotOffsetBottom;
}
}
if (result && e.getAction() == MotionEvent.ACTION_UP) {
onDragSelectionStop();
}
return result;
}
public void onScroll(RecyclerView recyclerView) {
AbstractMainViewHolder holder;
for (int i = 0; i < getItemCount(); i ++) {
holder = (AbstractMainViewHolder) recyclerView.findViewHolderForAdapterPosition(i);
if (holder != null && holder.getTop() < recyclerView.getMeasuredHeight()) {
holder.enterScreen(pendingAnimatorList, listAnimationEnabled);
}
}
}
private void updateSections(RecyclerView listView, boolean checkTopBottom) {
int count = listView.getChildCount();
int minPositionDateHolder = Integer.MAX_VALUE;
View minDateChild = null;
float padding = listView.getPaddingTop() + actionBar.getTranslationY();
int minTop = Integer.MAX_VALUE;
int maxBottom = 0;
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
int bottom = view.getBottom();
minTop = Math.min(minTop, view.getTop());
maxBottom = Math.max(bottom, maxBottom);
if (bottom <= padding) {
continue;
}
int position = view.getBottom();
if (view instanceof SharedMediaSectionCell || view instanceof GraySectionCell) {
if (view.getAlpha() != 1.0f) {
view.setAlpha(1.0f);
}
if (position < minPositionDateHolder) {
minPositionDateHolder = position;
minDateChild = view;
}
}
}
if (minDateChild != null) {
if (minDateChild.getTop() > padding) {
if (minDateChild.getAlpha() != 1.0f) {
minDateChild.setAlpha(1.0f);
}
} else {
if (minDateChild.getAlpha() != 0.0f) {
minDateChild.setAlpha(0.0f);
}
}
}
if (checkTopBottom) {
if (maxBottom != 0 && maxBottom < (listView.getMeasuredHeight() - listView.getPaddingBottom())) {
resetScroll();
} else if (minTop != Integer.MAX_VALUE && minTop > listView.getPaddingTop() + actionBar.getTranslationY()) {
scrollWithoutActionBar(listView, -listView.computeVerticalScrollOffset());
resetScroll();
}
}
}
private void updateSections(RecyclerView listView, boolean checkTopBottom) {
int count = listView.getChildCount();
int minPositionDateHolder = Integer.MAX_VALUE;
View minDateChild = null;
float padding = listView.getPaddingTop() + actionBar.getTranslationY();
int minTop = Integer.MAX_VALUE;
int maxBottom = 0;
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
int bottom = view.getBottom();
minTop = Math.min(minTop, view.getTop());
maxBottom = Math.max(bottom, maxBottom);
if (bottom <= padding) {
continue;
}
int position = view.getBottom();
if (view instanceof SharedMediaSectionCell || view instanceof GraySectionCell) {
if (view.getAlpha() != 1.0f) {
view.setAlpha(1.0f);
}
if (position < minPositionDateHolder) {
minPositionDateHolder = position;
minDateChild = view;
}
}
}
if (minDateChild != null) {
if (minDateChild.getTop() > padding) {
if (minDateChild.getAlpha() != 1.0f) {
minDateChild.setAlpha(1.0f);
}
} else {
if (minDateChild.getAlpha() != 0.0f) {
minDateChild.setAlpha(0.0f);
}
}
}
if (checkTopBottom) {
if (maxBottom != 0 && maxBottom < (listView.getMeasuredHeight() - listView.getPaddingBottom())) {
resetScroll();
} else if (minTop != Integer.MAX_VALUE && minTop > listView.getPaddingTop() + actionBar.getTranslationY()) {
scrollWithoutActionBar(listView, -listView.computeVerticalScrollOffset());
resetScroll();
}
}
}