can ViewGroup Child Scroll Down - Android User Interface

Android examples for User Interface:ViewGroup

Description

can ViewGroup Child Scroll Down

Demo Code


//package com.java2s;

import android.os.Build;
import android.support.v4.view.ViewCompat;

import android.view.View;
import android.view.ViewGroup;

import android.widget.AbsListView;
import android.widget.Adapter;

public class Main {
    public static boolean canChildScrollDown(ViewGroup viewGroup) {
        if (viewGroup != null) {
            View mListView = viewGroup.getChildAt(0);
            if (mListView != null) {
                if (Build.VERSION.SDK_INT < 14) {
                    if (mListView instanceof AbsListView) {
                        int childCount = ((AbsListView) mListView)
                                .getChildCount();
                        if (childCount <= 0) {
                            return false;
                        }//from  w w  w .j a v a  2s. co  m
                        Adapter adapter = ((AbsListView) mListView)
                                .getAdapter();
                        if (adapter == null || adapter.getCount() <= 0) {
                            return false;
                        }

                        if (((AbsListView) mListView)
                                .getLastVisiblePosition() < adapter
                                .getCount() - 1) {
                            return true;
                        }

                        int lastBottom = ((AbsListView) mListView)
                                .getChildAt(childCount - 1).getBottom();
                        int listBottom = mListView.getBottom();
                        return (lastBottom - listBottom) > mListView
                                .getPaddingBottom();
                    } else {
                        return ViewCompat.canScrollVertically(mListView, 1)
                                || mListView.getScrollY() > 0;
                    }
                } else {
                    return ViewCompat.canScrollVertically(mListView, 1);
                }
            }
        }
        return false;
    }
}

Related Tutorials