各View间继承关系

本文详细介绍了Android中View的继承关系,包括View、ViewGroup及其子类的层次结构,如SwipeRefreshLayout、RecyclerView等。此外,还阐述了接口与抽象类的概念区别,并列举了一些重要的接口,如NestedScrollingChild等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android view间继承关系:

这里写图片描述

这里写图片描述


public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource {public abstract class ViewGroup extends View implements ViewParent, ViewManager {public class SwipeRefreshLayout extends ViewGroup  
                                        implements NestedScrollingParent,NestedScrollingChild {public class SlidingPaneLayout extends ViewGroup {public class CoordinatorLayout extends ViewGroup implements NestedScrollingParent {public class RelativeLayout extends ViewGroup {public class RecyclerView extends ViewGroup 
                                    implements ScrollingView, NestedScrollingChild {public class FrameLayout extends ViewGroup {public class NestedScrollView extends FrameLayout 
                                            implements NestedScrollingParent, 
                                                        NestedScrollingChild, 
                                                        ScrollingView {public class TimePicker extends FrameLayout {public class DatePicker extends FrameLayout {public class CalendarView extends FrameLayout {public class ScrollView extends FrameLayout {public class HorizontalScrollView extends FrameLayout {public class TabLayout extends HorizontalScrollView {public class TabHost extends FrameLayout  
                                    implements ViewTreeObserver.OnTouchModeChangeListener {public class ViewAnimator extends FrameLayout {public class ViewFlipper extends ViewAnimator {public abstract class AdapterView<T extends Adapter> extends ViewGroup {public abstract class AbsListView extends AdapterView<ListAdapter>  
                                    implements TextWatcher,
                                        ViewTreeObserver.OnGlobalLayoutListener,  
                                        Filter.FilterListener,
                                        ViewTreeObserver.OnTouchModeChangeListener, 
                                        RemoteViewsAdapter.RemoteAdapterConnectionCallback {public class ListView extends AbsListView {public class ExpandableListView extends ListView {public class GridView extends AbsListView {public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {public class Spinner extends AbsSpinner implements OnClickListener {public class LinearLayout extends ViewGroup {public class AppBarLayout extends LinearLayout {public class TableLayout extends LinearLayout {public class RadioGroup extends LinearLayout {public class AbsoluteLayout extends ViewGroup {public class WebView extends AbsoluteLayout  
                                implements ViewTreeObserver.OnGlobalFocusChangeListener,  
                                            ViewGroup.OnHierarchyChangeListener,  
                                            ViewDebug.HierarchyHandler {public class SurfaceView extends View {public class VideoView extends SurfaceView  
                                implements MediaPlayerControl, SubtitleController.Anchor {public class TextView extends View implements ViewTreeObserver.OnPreDrawListener {public class EditText extends TextView {public class AutoCompleteTextView extends EditText implements Filter.FilterListener {public class AppCompatEditText extends EditText implements TintableBackgroundView {public class TextInputEditText extends AppCompatEditText {public class Button extends TextView {public abstract class CompoundButton extends Button implements Checkable {public class RadioButton extends CompoundButton {public class CheckBox extends CompoundButton {public class ProgressBar extends View {public abstract class AbsSeekBar extends ProgressBar {public class SeekBar extends AbsSeekBar {public class SearchView extends View {public class ImageView extends View {public class ImageButton extends ImageView {class VisibilityAwareImageButton extends ImageButton {public class FloatingActionButton extends VisibilityAwareImageButton {


//非view
public class Dialog implements DialogInterface, 
                            Window.Callback,KeyEvent.Callback,
                            OnCreateContextMenuListener, 
                            Window.OnWindowDismissedCallback {public class AlertDialog extends Dialog implements DialogInterface {public class ProgressDialog extends AlertDialog {


public class PopupWindow {


public class PopupMenu {


public interface Menu {


public class Notification implements Parcelable{

五大布局:

FrameLayout(框架布局)
LinearLayout(线性布局)
TableLayout(表格布局)
AbsoluteLayout(绝对布局)
RelativeLayout(相对布局)

另外注意:Menu、Dialog不为view。

public interface Menu {...}
public class Dialog implements DialogInterface, Callback, 
android.view.KeyEvent.Callback, OnCreateContextMenuListener {
...}

实现接口的一些view

public class View implements Callback, 
android.view.KeyEvent.Callback, AccessibilityEventSource {
...
}
public abstract class ViewGroup extends View 
implements ViewParent, ViewManager {

}
public class TextView extends View implements OnPreDrawListener 
{
...
}
public class WebView extends AbsoluteLayout 
implements OnGlobalFocusChangeListener, OnHierarchyChangeListener {...}
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild 
{
...
}
public abstract class AbsListView extends AdapterView<ListAdapter> implements TextWatcher, OnGlobalLayoutListener, 
FilterListener, OnTouchModeChangeListener 
{
...
}

接口与抽象类的知识:

接口:

public interface Sourceable {  
//1、接口中的方法一定是抽象方法,所以不用abstract修饰
//2、接口中不能赋予方法的默认行为,即不能有方法的具体实现,不需要大括号
//3、实现接口的一定要实现接口里定义的所有方法
//4、接口是公开的,里面不能有私有的方法或变量
//5、接口只可以继承一个或多个其它接口
//6、如果你想实现多重继承,那么你必须使用接口。由于Java不支持多继承,
//子类不能够继承多个类,但可以实现多个接口。因此你就可以使用接口来解决它。
 public void method1();  
 public void method2();  
}

抽象类:

public abstract class Wrapper2 implements Sourceable{  
//1、抽象类可以实现一个接口时,抽象类可以不实现接口的方法,由抽象类的子类实现
//2、抽象类可以没有抽象方法,但是如果你的一个类已经声明成了抽象类,
//即使这个类中没有抽象方法,它也不能再实例化,即不能直接构造一个该类的对象。
//3、如果一个类中有了一个抽象方法,那么这个类必须声明为抽象类,否则编译通不过。
//4、抽象类中可以赋予非抽象方法方法的默认行为,即方法的具体实现
//5、实现抽象类可以有选择地重写需要用到的方法,
//一般的应用里,最顶级的是接口,然后是抽象类实现接口,最后才到具体类实现。
//6、抽象类是可以有私有方法或私有变量的
//7、抽象方法可以继承一个类和实现多个接口
 public void method1(){}  
 public void method2(){}  
 }

一些接口的来源:

// 此接口使你可以向一个Activity中添加和移除子视图。
//调用Context.getSystemService(),你可以得到该类的一个实例。
//(译者注:ViewManager是个接口,没有任何实现,
//抽象类ViewGroup对该接口的三个方法进行了具体实现。)
public interface ViewManager {
    //增添一个视图对象,并指定其布局参数
    void addView(View var1, LayoutParams var2);

    //更新一个子视图
    void updateViewLayout(View var1, LayoutParams var2);

    //移除指定的视图  
    void removeView(View var1);
}
//能够在canvas上绘制,而且相比于View,
//并不需要去考虑measure、layout,仅仅只要去考虑如何draw(canavs)
public abstract class Drawable {
    public interface Callback {

         /** 
         * 当drawable重画时触发,这个点上drawable将被置为不可用
         * (起码drawable展示部分不可用) 
         * @param 要求重画的drawable 
         */  
        void invalidateDrawable(Drawable var1);

         /** 
         * drawable可以通过该方法来安排动画的下一帧。
         * 可以仅仅简单的调用postAtTime(Runnable, Object, long)来实现该方法。
         * 参数分别与方法的参数对应 
         * @param who The drawable being scheduled. 
         * @param what The action to execute. 
         * @param when The time (in milliseconds) to run 
         */ 
        void scheduleDrawable(Drawable var1, Runnable var2, long var3);

        /** 
         *可以用于取消先前通过scheduleDrawable(Drawable who, Runnable what, long when)调度的某一帧。
         可以通过调用removeCallbacks(Runnable,Object)来实现 
         * @param who The drawable being unscheduled. 
         * @param what The action being unscheduled. 
         */ 
        void unscheduleDrawable(Drawable var1, Runnable var2);
    }
}
//这是一个注册监听视图树的观察者(observer),在视图树中全局事件改变时得到通知。
//这个全局事件不仅还包括整个树的布局,从绘画过程开始,触摸模式的改变等。ViewTreeObserver不能够被应用程序实例化,
//因为它是由视图提供。
//view事件的观察者。要注意的是它的初始化就是调用View.getViewTreeObserver()。
public final class ViewTreeObserver {

//当一个视图树中的一些组件发生滚动时,所要调用的回调函数的接口类
  public interface OnScrollChangedListener {
        void onScrollChanged();
    }

 //当一个视图树的触摸模式发生改变时,所要调用的回调函数的接口类
    public interface OnTouchModeChangeListener {
        void onTouchModeChanged(boolean var1);
    }

    public interface OnDrawListener {
        void onDraw();
    }

 //当一个视图树将要绘制时,所要调用的回调函数的接口类
    public interface OnPreDrawListener {
        boolean onPreDraw();
    }

//当在一个视图树中全局布局发生改变或者视图树中的某个视图的可视状态发生改变时,所要调用的回调函数的接口类
    public interface OnGlobalLayoutListener {
        void onGlobalLayout();
    }

//当在一个视图树中的焦点状态发生改变时,所要调用的回调函数的接口类
    public interface OnGlobalFocusChangeListener {
        void onGlobalFocusChanged(View var1, View var2);
    }

    public interface OnWindowFocusChangeListener {
        void onWindowFocusChanged(boolean var1);
    }

    public interface OnWindowAttachListener {
        void onWindowAttached();

        void onWindowDetached();
    }

}
public interface TextWatcher extends NoCopySpan {
    void beforeTextChanged(CharSequence var1, int var2, int var3, int var4);

    void onTextChanged(CharSequence var1, int var2, int var3, int var4);

    void afterTextChanged(Editable var1);
}
public abstract class Filter
{
        public interface FilterListener {
        void onFilterComplete(int var1);
    }
}
public interface NestedScrollingChild {

    public void setNestedScrollingEnabled(boolean enabled);

    public boolean isNestedScrollingEnabled();

    public boolean startNestedScroll(int axes);

    public void stopNestedScroll();

    public boolean hasNestedScrollingParent();

    public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed,
            int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow);

    public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow);

    public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed);

    public boolean dispatchNestedPreFling(float velocityX, float velocityY);
}
public interface NoCopySpan {
    public static class Concrete implements NoCopySpan {
        public Concrete() {
            throw new RuntimeException("Stub!");
        }
    }
}

参考:

ViewTreeObserver简介

Android 3.0 r1中文API文档(104) —— ViewTreeObserver

Java抽象类与接口的区别

android中文api(89)——ViewManager

Android Drawable 那些不为人知的高效用法

Android 3.0 r1中文API文档(104) —— ViewTreeObserver

getViewTreeObserver

在OnCreate()中获取控件高度与宽度:

ViewTreeObserver observer = view.getViewTreeObserver();    
observer .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {    
           @Override    
           public void onGlobalLayout() {    
              view.getViewTreeObserver().removeGlobalOnLayoutListener(this);    
    final int w = view.getMeasuredWidth();  
    final int h = view.getMeasuredHeight();  
           }    
       }); 

启动帧动画

使用ViewTreeObserver.OnPreDrawListener listener:当一个视图树将要绘制时产生事件,可以添加一个其事件处理函数:onPreDraw

OnPreDrawListener opdl=new OnPreDrawListener(){  
        @Override  
        public boolean onPreDraw() {  
            animDraw.start();  
            return true;  
        }  
    };  

//onCreate方法中  
imageV.getViewTreeObserver().addOnPreDrawListener(opdl); 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值