is First Child View On Top - Android User Interface

Android examples for User Interface:View Child

Description

is First Child View On Top

Demo Code


//package com.java2s;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ScrollView;

public class Main {
    public static boolean isFirstChildOnTop(View view) {
        if (view == null) {
            return true;
        }/*from   w ww  .j a v  a  2  s .  com*/

        if (view instanceof AbsListView) {
            return isFirstChildOnTopInAbsListView((AbsListView) view);
        } else if (view instanceof ScrollView) {
            return isFirstChildOnTopInScrollView((ScrollView) view);
        } else {
            return true;
        }
    }

    private static boolean isFirstChildOnTopInAbsListView(
            AbsListView listView) {
        int firstVisiblePosition = listView.getFirstVisiblePosition();
        if (firstVisiblePosition == 0) {
            final View child = listView.getChildAt(0);
            int top = child.getTop();
            return top >= 0;
        } else {
            return false;
        }
    }

    private static boolean isFirstChildOnTopInScrollView(
            ScrollView scrollView) {
        int scrollY = scrollView.getScrollY();
        return scrollY <= 0;
    }
}

Related Tutorials