Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package android.view;
     17 
     18 import android.content.Context;
     19 import android.graphics.drawable.Drawable;
     20 
     21 /**
     22  * A group overlay is an extra layer that sits on top of a ViewGroup
     23  * (the "host view") which is drawn after all other content in that view
     24  * (including the view group's children). Interaction with the overlay
     25  * layer is done by adding and removing views and drawables.
     26  *
     27  * <p>ViewGroupOverlay is a subclass of {@link ViewOverlay}, adding the ability to
     28  * manage views for overlays on ViewGroups, in addition to the drawable
     29  * support in ViewOverlay.</p>
     30  *
     31  * @see ViewGroup#getOverlay()
     32  */
     33 public class ViewGroupOverlay extends ViewOverlay {
     34 
     35     ViewGroupOverlay(Context context, View hostView) {
     36         super(context, hostView);
     37     }
     38 
     39     /**
     40      * Adds a View to the overlay. The bounds of the added view should be
     41      * relative to the host view. Any view added to the overlay should be
     42      * removed when it is no longer needed or no longer visible.
     43      *
     44      * <p>Views in the overlay are visual-only; they do not receive input
     45      * events and do not participate in focus traversal. Overlay views
     46      * are intended to be transient, such as might be needed by a temporary
     47      * animation effect.</p>
     48      *
     49      * <p>If the view has a parent, the view will be removed from that parent
     50      * before being added to the overlay. Also, if that parent is attached
     51      * in the current view hierarchy, the view will be repositioned
     52      * such that it is in the same relative location inside the activity. For
     53      * example, if the view's current parent lies 100 pixels to the right
     54      * and 200 pixels down from the origin of the overlay's
     55      * host view, then the view will be offset by (100, 200).</p>
     56      *
     57      * @param view The View to be added to the overlay. The added view will be
     58      * drawn when the overlay is drawn.
     59      * @see #remove(View)
     60      * @see ViewOverlay#add(Drawable)
     61      */
     62     public void add(View view) {
     63         mOverlayViewGroup.add(view);
     64     }
     65 
     66     /**
     67      * Removes the specified View from the overlay.
     68      *
     69      * @param view The View to be removed from the overlay.
     70      * @see #add(View)
     71      * @see ViewOverlay#remove(Drawable)
     72      */
     73     public void remove(View view) {
     74         mOverlayViewGroup.remove(view);
     75     }
     76 }
     77