private static NestedScrollView findAncestorNestedScrollView(View v) {
ViewParent target = v.getParent();
while (target != null) {
if (target instanceof NestedScrollView) {
return (NestedScrollView) target;
target = target.getParent();
return null;
public static int getViewLevel(View view) {
int level = 0;
ViewParent parent = view.getParent();
while (parent != null && !parent.toString().contains("android.view.ViewRootImpl")) {
parent = parent.getParent();
level++;
return level;
@Override public void onStartTrackingTouch(SeekBar seekBar) { Log.i(TAG, "bottomProgress onStartTrackingTouch [" + this.hashCode() + "] "); cancelProgressTimer(); ViewParent vpdown = getParent(); while (vpdown != null) { vpdown.requestDisallowInterceptTouchEvent(true); vpdown = vpdown.getParent();
@Override public void onStartTrackingTouch(SeekBar seekBar) { Log.i(TAG, "bottomProgress onStartTrackingTouch [" + this.hashCode() + "] "); cancelProgressTimer(); ViewParent vpdown = getParent(); while (vpdown != null) { vpdown.requestDisallowInterceptTouchEvent(true); vpdown = vpdown.getParent();
private AdapterView findParentAdapterView() {
if (parentAdapter != null) {
return parentAdapter;
ViewParent current = getParent();
while (true
) {
if (current instanceof AdapterView) {
parentAdapter = (AdapterView) current;
return parentAdapter;
} else {
try {
current = current.getParent();
} catch (NullPointerException npe) {
throw new RuntimeException("Could not find a parent AdapterView");
@Override public void onStopTrackingTouch(SeekBar seekBar) { Log.i(TAG, "bottomProgress onStopTrackingTouch [" + this.hashCode() + "] "); onEvent(JZUserAction.ON_SEEK_POSITION); startProgressTimer(); ViewParent vpup = getParent(); while (vpup != null) { vpup.requestDisallowInterceptTouchEvent(false); vpup = vpup.getParent(); if (currentState != CURRENT_STATE_PLAYING && currentState != CURRENT_STATE_PAUSE) return; long time = seekBar.getProgress() * getDuration() / 100; seekToManulPosition = seekBar.getProgress(); JZMediaManager.seekTo(time); Log.i(TAG, "seekTo " + time + " [" + this.hashCode() + "] ");
private boolean isInScrollingContainer() {
ViewParent p = getParent();
while (p != null && p instanceof ViewGroup) {
if (((ViewGroup) p).shouldDelayChildPressedState()) {
return true;
p = p.getParent();
return false;
private boolean isInScrollingContainer() {
ViewParent p = getParent();
while (p != null && p instanceof ViewGroup) {
if (((ViewGroup) p).shouldDelayChildPressedState()) {
return true;
p = p.getParent();
return false;
@Override public void requestLayout() { // Don't request a layout if it will be blocked by any parent. Requesting a layout that is // then ignored by an ancestor means that this host will remain in a state where it thinks that // it has requested layout, and will therefore ignore future layout requests. This will lead to // problems if a child (e.g. a ViewPager) requests a layout later on, since the request will be // wrongly ignored by this host. ViewParent parent = this; while (parent instanceof ComponentHost) { final ComponentHost host = (ComponentHost) parent; if (!host.shouldRequestLayout()) { return; parent = parent.getParent(); super.requestLayout();
@Override public boolean matchesSafely(View view) { boolean found = false; ViewParent parent = view.getParent(); while (!found && parent != null) { found = viewMatcher.matches(parent); parent = parent.getParent(); return found;
/**
* 在当前布局中查找AppBarLayout并返回,没有找到返回null
* #解决和AppBarLayout自身滚动冲突的问题#
public static AppBarLayout findAppBarLayout(View v) {
AppBarLayout appBarLayout = null;
ViewParent p = v.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;
return appBarLayout;
@Override public void onStopTrackingTouch(SeekBar seekBar) { Log.i(TAG, "bottomProgress onStopTrackingTouch [" + this.hashCode() + "] "); onEvent(JCBuriedPoint.ON_SEEK_POSITION); startProgressTimer(); ViewParent vpup = getParent(); while (vpup != null) { vpup.requestDisallowInterceptTouchEvent(false); vpup = vpup.getParent(); if (currentState != CURRENT_STATE_PLAYING && currentState != CURRENT_STATE_PAUSE) return; int time = seekBar.getProgress() * getDuration() / 100; JCMediaManager.instance().mediaPlayer.seekTo(time); Log.i(TAG, "seekTo " + time + " [" + this.hashCode() + "] ");
viewParent = viewParent.getParent();
/**
* Provide a nested string representation of a LithoView and its nested components for debugging
* purposes.
* @param view A Litho view with mounted components.
* @param embedded if the call is embedded in "adb dumpsys activity"
@DoNotStrip
public static String viewToString(LithoView view, boolean embedded) {
int left = 0;
int top = 0;
int depth = 0;
if (embedded) {
left = view.getLeft();
top = view.getTop();
depth = 2;
ViewParent parent = view.getParent();
while (parent != null) {
depth++;
parent = parent.getParent();
final StringBuilder sb = new StringBuilder();
viewToString(left, top, DebugComponent.getRootInstance(view), sb, embedded, depth);
return sb.toString();
ViewGroup containerParent = (ViewGroup) homeBtnContainer.
getParent();
return "An ancestor View has importantForAccessibility set to 'NO_HIDE_DESCENDANTS'.";
parent = parent.getParent();
break;
p = p.getParent();
break;
p = p.getParent();