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!");
}
}
}
参考:
Android 3.0 r1中文API文档(104) —— ViewTreeObserver
Android 3.0 r1中文API文档(104) —— ViewTreeObserver
在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);