publicvoidplayTogether(Animator... items){ Builder builder = play(items[0]); for (int i = 1; i < items.length; ++i) { builder.with(items[i]); } }
with 方法会在兄弟节点集合中添加代表下一个动画的 Node 节点。
至于 after 方法自然就是添加到父节点集合中去了,此外 after 方法还能够设置延迟,这是通过插入一个时长为 delay 的空动画来实现的。
1 2 3 4 5 6 7
public Builder after(long delay){ // setup dummy ValueAnimator just to run the clock ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); anim.setDuration(delay); after(anim); returnthis; }
@Override publicvoiddraw(Canvas canvas){ final Rect r = getBounds(); final ShapeState state = mShapeState; final Paint paint = state.mPaint; finalint count = canvas.save(); canvas.translate(r.left, r.top); shape.draw(canvas, paint); canvas.restoreToCount(count); }
@Override publicvoiddraw(Canvas canvas){ final ChildDrawable[] array = mLayerState.mChildren; finalint N = mLayerState.mNum; for (int i = 0; i < N; i++) { final Drawable dr = array[i].mDrawable; if (dr != null) { dr.draw(canvas); } } }
@Override protectedvoidonLayout(boolean changed, int left, int top, int right, int bottom){ super.onLayout(changed, left, top, right, bottom); if(changed){ mPath = new Path(); int width = getWidth(); int height = getHeight(); int radius = Math.min(width/2, height/2); mPath.addCircle(getWidth()/2, getHeight()/2, radius, Path.Direction.CW); } }
/** * @param text the text to render * @param paint the default paint for the layout. Styles can override * various attributes of the paint. * @param width the wrapping width for the text. * @param align whether to left, right, or center the text. Styles can * override the alignment. * @param spacingMult factor by which to scale the font size to get the * default line spacing * @param spacingAdd amount to add to the default line spacing */ protectedLayout(CharSequence text, TextPaint paint, int width, Alignment align, TextDirectionHeuristic textDir, float spacingMult, float spacingAdd)
绘制方法包括两步,即按行绘制文本即行背景。
Layout 有很多获取和设置布局的信息,如
1.获得某画笔类TextPaint下的文本宽度
1
publicstaticfloatgetDesiredWidth(CharSequence source, int start, int end, TextPaint paint)
privateintgetEdgesTouched(int x, int y){ int result = 0; if (x < mParentView.getLeft() + mEdgeSize) result |= EDGE_LEFT; if (y < mParentView.getTop() + mEdgeSize) result |= EDGE_TOP; if (x > mParentView.getRight() - mEdgeSize) result |= EDGE_RIGHT; if (y > mParentView.getBottom() - mEdgeSize) result |= EDGE_BOTTOM; return result; }
@Nullable public ActionBar getActionBar(){ Window window = getWindow(); if (!window.hasFeature(Window.FEATURE_ACTION_BAR) || mActionBar != null) return; mActionBar = new WindowDecorActionBar(this); return mActionBar; }
如果没有,可以正常进行,新建的实现类是 ToolbarActionBar。
1 2 3 4 5 6 7 8 9
publicvoidsetActionBar(@Nullable Toolbar toolbar){ if (getActionBar() instanceof WindowDecorActionBar) { thrownew IllegalStateException("This Activity already has an action bar supplied " + "by the window decor. Do not request Window.FEATURE_ACTION_BAR and set " + "android:windowActionBar to false in your theme to use a Toolbar instead."); } ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this); mActionBar = tbab; mActionBar.invalidateOptionsMenu(); }
可见 ActionBar 和 Toolbar 是表里的关系。你可以处理菜单相关的事项
1 2 3 4 5
Menu getMenu(); inflateMenu(R.menu.menu_main); booleanshowOverflowMenu(); //通过反射修改显示 OverflowMenu booleanhideOverflowMenu(); voidsetOnMenuItemClickListener(OnMenuItemClickListener listener);
/** * @param x Edge of the replacement closest to the leading margin. * @param top Top of the line. * @param y Baseline. * @param bottom Bottom of the line. * @param paint Paint instance. */ publicabstractvoiddraw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0)int start, @IntRange(from = 0)int end, float x, int top, int y, int bottom, @NonNull Paint paint);