show Child View - Android User Interface

Android examples for User Interface:View Child

Description

show Child View

Demo Code


//package com.java2s;

import android.view.View;

import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;

public class Main {
    private static long ANIMATE_DURATION = 200;

    public static void showChild(View parent, int child) {
        showChild(parent, parent.findViewById(child));
    }// www .j av  a 2 s .  c om

    public static void showChild(View parent, View child) {
        if (!(parent instanceof ViewGroup)) {
            return;
        }
        ViewGroup g = (ViewGroup) parent;
        for (int i = 0; i < g.getChildCount(); ++i) {
            View v = g.getChildAt(i);
            if (v == child) {
                showView(v, false);
                v.bringToFront();
            } else {
                goneView(v, false);
            }
        }
    }

    public static View showView(View v, boolean animate, long duration) {
        if (v != null) {
            v.setVisibility(View.VISIBLE);
            if (animate) {
                Animation ani = new AlphaAnimation(0f, 1f);
                ani.setDuration(duration);
                v.startAnimation(ani);
            }
        }
        return v;
    }

    public static View showView(View v, boolean animate) {
        return showView(v, animate, ANIMATE_DURATION);
    }

    public static View goneView(View v, boolean animate) {
        if (v != null) {
            v.setVisibility(View.GONE);
            if (animate) {
                Animation ani = new AlphaAnimation(1f, 0f);
                ani.setDuration(ANIMATE_DURATION);
                v.startAnimation(ani);
            }
        }
        return v;
    }
}

Related Tutorials