public void showLikeQuickAction(int x, int y) { preShow(); mWindow.setAnimationStyle(android.R.style.Animation_Dialog); int[] location = new int[2]; mAnchor.getLocationOnScreen(location); Rect anchorRect = new Rect( location[0], location[1], location[0] + mAnchor.getWidth(), location[1] + mAnchor.getHeight()); root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int rootW = root.getWidth(), rootH = root.getHeight(); int screenW = mWManager.getDefaultDisplay().getWidth(); int xpos = ((screenW - rootW) / 2) + x; int ypos = anchorRect.top - rootH + y; if (rootH > anchorRect.top) { ypos = anchorRect.bottom + y; } mWindow.showAtLocation(mAnchor, Gravity.NO_GRAVITY, xpos, ypos); }
@Override // left是child的坐标,dx是坐标变化量,返回值表示child的新位置 public int clampViewPositionHorizontal(View child, int left, int dx) { // Log.i("mDragHelperCallback", "clampViewPositionHorizontal"); if (child == ZztSwipeLayout.this.surfacechildview) { if (left >= 0) { ZztSwipeLayout.this.setZztSwipeLayoutStatus(Status.Close); if (ZztSwipeLayout.this.iStatusListener != null) ZztSwipeLayout.this.iStatusListener.onClose(); return 0; } else if (left > (-ZztSwipeLayout.this.bottomchildview.getWidth())) return left; else if (left <= (-ZztSwipeLayout.this.bottomchildview.getWidth())) { ZztSwipeLayout.this.setZztSwipeLayoutStatus(Status.Open); if (ZztSwipeLayout.this.iStatusListener != null) ZztSwipeLayout.this.iStatusListener.onOpen( ZztSwipeLayout.this, ZztSwipeLayout.this.iStatusListener.getPosition()); return -ZztSwipeLayout.this.bottomchildview.getWidth(); } } else if (child == ZztSwipeLayout.this.bottomchildview) { if (left <= ZztSwipeLayout.this.getWidth() - child.getWidth()) return ZztSwipeLayout.this.getWidth() - child.getWidth(); else if (left >= ZztSwipeLayout.this.getWidth()) return ZztSwipeLayout.this.getWidth(); return left; } return 0; }
private void setPosition(View v, int dx, int dy) { int parentWidth = this.getWidth(); int parentHeight = this.getHeight(); int l = v.getLeft() + dx; int t = v.getTop() + dy; if (l < 0) { l = 0; } else if ((l + v.getWidth()) >= parentWidth) { l = parentWidth - v.getWidth(); } if (t < 0) { t = 0; } else if ((t + v.getHeight()) >= parentHeight) { t = parentHeight - v.getHeight(); } int r = l + v.getWidth(); int b = t + v.getHeight(); v.layout(l, t, r, b); RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams(); params.leftMargin = l; params.topMargin = t; v.setLayoutParams(params); }
private static void drawToast(View v, Rect vRect) { // TODO Auto-generated method stub if (mToast != null) { View tv = mToast.getView(); if (tv.getWidth() > 0 && tv.isShown()) { if (LOGD_ENABLED) Log.i(LOG_TAG, "==== " + tv.getWidth() + " " + tv.getHeight()); Bitmap second = Utils.createPngScreenshot(tv, tv.getWidth(), tv.getHeight(), 0); if (LOGD_ENABLED) Log.d( LOG_TAG, "====== gravity " + mToast.getGravity() + " x y " + mToast.getXOffset() + " " + mToast.getYOffset() + " " + mToast.getHorizontalMargin() + " " + mToast.getVerticalMargin()); PointF fromPoint = new PointF( (v.getWidth() - tv.getWidth()) / 2, v.getHeight() - vRect.top - mToast.getYOffset() - tv.getHeight()); if (LOGD_ENABLED) Log.i(LOG_TAG, "======= prepare menu view2 ========" + fromPoint.x + " " + fromPoint.y); mCapture = Utils.mixtureBitmap2(mCapture, second, fromPoint, 0, (float) 1.0); } } }
private void startAnimation(final boolean isLeft, final boolean isOpen, boolean staticDuration) { mToOpen = isOpen; int total; if (isLeft) { mTargetView = mLeftDrawer; mStartLeft = mLeftDrawer.getLeft(); total = mLeftDrawer.getWidth(); mEndLeft = mToOpen ? 0 : -total; } else { mTargetView = mRightDrawer; mStartLeft = mRightDrawer.getLeft(); total = mRightDrawer.getWidth(); mEndLeft = mToOpen ? getWidth() - total : getWidth(); } if (mStartLeft == mEndLeft) { // No need to animate updateDrawerSlide(mTargetView, mToOpen ? 1.0f : 0.0f); updateDrawerState(mTargetView, mToOpen ? STATE_OPEN : STATE_CLOSED); if (mToOpen) dispatchOnDrawerOpened(mTargetView); else dispatchOnDrawerClosed(mTargetView); return; } mAnimator.setDuration( staticDuration ? ANIMATE_TIME : ANIMATE_TIME * Math.abs(mStartLeft - mEndLeft) / total); mAnimator.start(); }
public static Bitmap getViewBitmap(View v) { if (v.getWidth() == 0 || v.getHeight() == 0) return null; Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.draw(c); return b; }
@Override /** * - Capture the clicked cluster so we can use it in custom infoWindow - Check overall bounds of * items in cluster - If the bounds are empty (all hosts at same place) then let it pop the info * window - Otherwise, move the camera to show the bounds of the map */ public boolean onClusterClick(Cluster<HostBriefInfo> cluster) { mLastClickedCluster = cluster; // remember for use later in the Adapter // Find out the bounds of the hosts currently in cluster LatLngBounds.Builder builder = new LatLngBounds.Builder(); for (HostBriefInfo host : cluster.getItems()) { builder.include(host.getLatLng()); } LatLngBounds bounds = builder.build(); // If the hosts are not all at the same location, then change bounds of map. if (!bounds.southwest.equals(bounds.northeast)) { // Offset from edge of map in pixels when exploding cluster View mapView = findViewById(R.id.map_fragment); int padding_percent = getResources().getInteger(R.integer.cluster_explode_padding_percent); int padding = Math.min(mapView.getHeight(), mapView.getWidth()) * padding_percent / 100; CameraUpdate cu = CameraUpdateFactory.newLatLngBounds( bounds, mapView.getWidth(), mapView.getHeight(), padding); mMap.animateCamera(cu); return true; } showMultihostSelectDialog((ArrayList<HostBriefInfo>) cluster.getItems()); return true; }
/** 在拖动的时候执行 */ @Override protected void onScrollChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4) { // TODO Auto-generated method stub super.onScrollChanged(paramInt1, paramInt2, paramInt3, paramInt4); shade_ShowOrHide(); if (!activity.isFinishing() && ll_content != null && leftImage != null && rightImage != null && ll_more != null && rl_column != null) { if (ll_content.getWidth() <= mScreenWitdh) { leftImage.setVisibility(View.GONE); rightImage.setVisibility(View.GONE); } } else { return; } if (paramInt1 == 0) { leftImage.setVisibility(View.GONE); rightImage.setVisibility(View.VISIBLE); return; } if (ll_content.getWidth() - paramInt1 + ll_more.getWidth() + rl_column.getLeft() == mScreenWitdh) { leftImage.setVisibility(View.VISIBLE); rightImage.setVisibility(View.GONE); return; } leftImage.setVisibility(View.VISIBLE); rightImage.setVisibility(View.VISIBLE); }
private float getTranslateX(float progress) { final int fairyEndX = mContentView.getWidth() / 2; final int fairyStartX = mImageViewFairy.getWidth() / 2; final int maxTravelDistance = Math.min(fairyEndX - fairyStartX, mContentView.getWidth() - mFairyContainer.getWidth()); return maxTravelDistance * (progress / 100); }
private void trySlideAttachmentView(final ViewWrapper viewWrapper) { if (!(viewWrapper.attachment instanceof MediaPickerMessagePartData)) { return; } final View view = viewWrapper.view; final int xOffset = viewWrapper.prevLeft - view.getLeft(); final int yOffset = viewWrapper.prevTop - view.getTop(); final float scaleX = viewWrapper.prevWidth / (float) view.getWidth(); final float scaleY = viewWrapper.prevHeight / (float) view.getHeight(); if (xOffset == 0 && yOffset == 0 && scaleX == 1 && scaleY == 1) { // Layout hasn't changed return; } final AnimationSet animationSet = new AnimationSet(true /* shareInterpolator */); animationSet.addAnimation(new TranslateAnimation(xOffset, 0, yOffset, 0)); animationSet.addAnimation(new ScaleAnimation(scaleX, 1, scaleY, 1)); animationSet.setDuration(UiUtils.MEDIAPICKER_TRANSITION_DURATION); animationSet.setInterpolator(UiUtils.DEFAULT_INTERPOLATOR); view.startAnimation(animationSet); view.invalidate(); viewWrapper.prevLeft = view.getLeft(); viewWrapper.prevTop = view.getTop(); viewWrapper.prevWidth = view.getWidth(); viewWrapper.prevHeight = view.getHeight(); }
private void updateIndicatorPosition(int position, float positionOffset) { // 現在の位置のタブのView final View view = mTrack.getChildAt(position); // 現在の位置の次のタブのView、現在の位置が最後のタブのときはnull final View view2 = position == (mTrack.getChildCount() - 1) ? null : mTrack.getChildAt(position + 1); // 現在の位置のタブの左端座標取得 int left = view.getLeft(); // 現在の位置のタブの横幅 int width = view.getWidth(); // 現在の位置の次のタブの横幅 int width2 = view2 == null ? width : view2.getWidth(); // インディケータの幅 // width2 × スライドした割合 + (width × スライドした割合 - 1) int indicatorWidth = (int) (width2 * positionOffset + width * (1 - positionOffset)); // インディケータの左端の位置 // 今選択中のタブの左端 + width * スライドした割合 int indicatorLeft = (int) (left + positionOffset * width); // インディケータの幅と左端の位置をセット final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mIndicator.getLayoutParams(); layoutParams.width = indicatorWidth; layoutParams.setMargins(indicatorLeft, 0, 0, 0); mIndicator.setLayoutParams(layoutParams); // インディケータが画面に入るように、タブの領域をスクロール mTrackScroller.scrollTo(indicatorLeft - mIndicatorOffset, 0); mIndicator.setBackgroundColor(getResources().getColor(R.color.ferrari_red)); }
public boolean onSwipe(MotionEvent event) { mGestureDetector.onTouchEvent(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mDownX = (int) event.getX(); isFling = false; break; case MotionEvent.ACTION_MOVE: int dis = (int) (mDownX - event.getX()); if (state == STATE_OPEN) { dis += mMenuView.getWidth() * mSwipeDirection; } swipe(dis); break; case MotionEvent.ACTION_UP: if ((isFling || Math.abs(mDownX - event.getX()) > (mMenuView.getWidth() / 3)) && Math.signum(mDownX - event.getX()) == mSwipeDirection) { smoothOpenMenu(); } else { smoothCloseMenu(); return false; } break; } return true; }
private void initSlideMode() { mCloseOnRelease = false; View v = getChildAt(1); if (mMode == MODE_READY) { mStartOffset = 0; mEndOffset = mDirection * getChildAt(0).getWidth(); } else { mStartOffset = mDirection * getChildAt(0).getWidth(); mEndOffset = 0; } mOffset = mStartOffset; if (mCachedBitmap == null || mCachedBitmap.isRecycled() || mCachedBitmap.getWidth() != v.getWidth()) { mCachedBitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); mCachedCanvas = new Canvas(mCachedBitmap); } else { mCachedCanvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); } v.setVisibility(View.VISIBLE); mCachedCanvas.translate(-v.getScrollX(), -v.getScrollY()); v.draw(mCachedCanvas); mMode = MODE_SLIDE; mMenuView.setVisibility(View.VISIBLE); }
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); int childCount = recyclerView.getChildCount(); int width = recyclerView.getChildAt(0).getWidth(); int padding = (recyclerView.getWidth() - width) / 2; for (int i = 0; i < childCount; i++) { View view = recyclerView.getChildAt(i); float ratio = 0; if (view.getLeft() <= padding) { if (view.getLeft() >= padding - view.getWidth()) { ratio = (padding - view.getLeft()) * 1f / view.getWidth(); } else { ratio = 1; } view.setScaleY(1 - ratio * 0.5f); view.setScaleX(1 - ratio * 0.5f); } else { if (view.getLeft() <= recyclerView.getWidth() - padding) { ratio = (recyclerView.getWidth() - padding - view.getLeft()) * 1f / view.getWidth(); } view.setScaleY(0.5f + ratio * 0.5f); view.setScaleX(0.5f + ratio * 0.5f); } } }
@Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: oldX = event.getRawX(); newX = event.getRawX(); break; case MotionEvent.ACTION_MOVE: newX = event.getRawX(); if (v != layout) { v.setTranslationX((newX - oldX) * 1.075f); if (v.getX() > v.getWidth() - 150 || v.getX() < -v.getWidth() + 150) { contentFrameLayout.removeView(v); } } else { if (newX - oldX > 50) { int distance = (int) (newX - oldX); if (distance > v.getWidth() / 2) ; { finish(); overridePendingTransition(R.anim.side_in_left, R.anim.slide_out_right); } } } break; case MotionEvent.ACTION_UP: if (v != layout) { v.setTranslationX(0); } break; } return true; }
private void hide(final View myView) { // get the center for the clipping circle int cx = myView.getWidth() / 2; int cy = myView.getHeight() / 2; // get the initial radius for the clipping circle int initialRadius = myView.getWidth(); // create the animation (the final radius is zero) Animator anim = null; if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) { anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0); } // make the view invisible when the animation is done anim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); myView.setVisibility(View.INVISIBLE); } }); // start the animation if (anim != null) { anim.start(); } }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (getChildCount() == 0) { return; } final Drawable d = indicator; View tabView = tabWidget.getChildTabViewAt(position); if (tabView == null) { return; } View nextTabView = position + 1 < tabWidget.getTabCount() ? tabWidget.getChildTabViewAt(position + 1) : null; int tabWidth = tabView.getWidth(); int nextTabWidth = nextTabView == null ? tabWidth : nextTabView.getWidth(); int indicatorWidth = (int) (nextTabWidth * positionOffset + tabWidth * (1 - positionOffset)); int indicatorLeft = (int) (getPaddingLeft() + tabView.getLeft() + positionOffset * tabWidth); int height = getHeight(); d.setBounds(indicatorLeft, height - indicatorHeight, indicatorLeft + indicatorWidth, height); d.draw(canvas); }
private void calcIndicatorRect() { View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab); float left = currentTabView.getLeft(); float right = currentTabView.getRight(); // for mIndicatorWidthEqualTitle if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) { TextView tab_title = (TextView) currentTabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tab_title.getText().toString()); margin = (right - left - textWidth) / 2; } if (this.mCurrentTab < mTabCount - 1) { View nextTabView = mTabsContainer.getChildAt(this.mCurrentTab + 1); float nextTabLeft = nextTabView.getLeft(); float nextTabRight = nextTabView.getRight(); left = left + mCurrentPositionOffset * (nextTabLeft - left); right = right + mCurrentPositionOffset * (nextTabRight - right); // for mIndicatorWidthEqualTitle if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) { TextView next_tab_title = (TextView) nextTabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float nextTextWidth = mTextPaint.measureText(next_tab_title.getText().toString()); float nextMargin = (nextTabRight - nextTabLeft - nextTextWidth) / 2; margin = margin + mCurrentPositionOffset * (nextMargin - margin); } } mIndicatorRect.left = (int) left; mIndicatorRect.right = (int) right; // for mIndicatorWidthEqualTitle if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) { mIndicatorRect.left = (int) (left + margin - 1); mIndicatorRect.right = (int) (right - margin - 1); } mTabRect.left = (int) left; mTabRect.right = (int) right; if (mIndicatorWidth < 0) { // indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip } else { // indicatorWidth大于0时,圆角矩形以及三角形 float indicatorLeft = currentTabView.getLeft() + (currentTabView.getWidth() - mIndicatorWidth) / 2; if (this.mCurrentTab < mTabCount - 1) { View nextTab = mTabsContainer.getChildAt(this.mCurrentTab + 1); indicatorLeft = indicatorLeft + mCurrentPositionOffset * (currentTabView.getWidth() / 2 + nextTab.getWidth() / 2); } mIndicatorRect.left = (int) indicatorLeft; mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth); } }
private void drawDebugInfo(Canvas canvas, View child) { if (!debugDraw) { return; } Paint childPaint = this.createPaint(0xffffff00); Paint layoutPaint = this.createPaint(0xff00ff00); Paint newLinePaint = this.createPaint(0xffff0000); LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.horizontalSpacing > 0) { float x = child.getRight(); float y = child.getTop() + child.getHeight() / 2.0f; canvas.drawLine(x, y, x + lp.horizontalSpacing, y, childPaint); canvas.drawLine( x + lp.horizontalSpacing - 4.0f, y - 4.0f, x + lp.horizontalSpacing, y, childPaint); canvas.drawLine( x + lp.horizontalSpacing - 4.0f, y + 4.0f, x + lp.horizontalSpacing, y, childPaint); } else if (this.horizontalSpacing > 0) { float x = child.getRight(); float y = child.getTop() + child.getHeight() / 2.0f; canvas.drawLine(x, y, x + this.horizontalSpacing, y, layoutPaint); canvas.drawLine( x + this.horizontalSpacing - 4.0f, y - 4.0f, x + this.horizontalSpacing, y, layoutPaint); canvas.drawLine( x + this.horizontalSpacing - 4.0f, y + 4.0f, x + this.horizontalSpacing, y, layoutPaint); } if (lp.verticalSpacing > 0) { float x = child.getLeft() + child.getWidth() / 2.0f; float y = child.getBottom(); canvas.drawLine(x, y, x, y + lp.verticalSpacing, childPaint); canvas.drawLine( x - 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint); canvas.drawLine( x + 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint); } else if (this.verticalSpacing > 0) { float x = child.getLeft() + child.getWidth() / 2.0f; float y = child.getBottom(); canvas.drawLine(x, y, x, y + this.verticalSpacing, layoutPaint); canvas.drawLine( x - 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint); canvas.drawLine( x + 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint); } if (lp.newLine) { if (orientation == HORIZONTAL) { float x = child.getLeft(); float y = child.getTop() + child.getHeight() / 2.0f; canvas.drawLine(x, y - 6.0f, x, y + 6.0f, newLinePaint); } else { float x = child.getLeft() + child.getWidth() / 2.0f; float y = child.getTop(); canvas.drawLine(x - 6.0f, y, x + 6.0f, y, newLinePaint); } } }
@Test public void layout_shouldAffectWidthAndHeight() throws Exception { assertThat(view.getWidth(), equalTo(0)); assertThat(view.getHeight(), equalTo(0)); view.layout(100, 200, 303, 404); assertThat(view.getWidth(), equalTo(303 - 100)); assertThat(view.getHeight(), equalTo(404 - 200)); }
public void smoothOpenMenu() { state = STATE_OPEN; if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) { mOpenScroller.startScroll(-mContentView.getLeft(), 0, mMenuView.getWidth(), 0, animDuration); } else { mOpenScroller.startScroll(mContentView.getLeft(), 0, mMenuView.getWidth(), 0, animDuration); } postInvalidate(); }
@Override public int clampViewPositionHorizontal(View child, int left, int dx) { int ret = 0; if ((mTrackingEdge & EDGE_LEFT) != 0) { ret = Math.min(child.getWidth(), Math.max(left, 0)); } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { ret = Math.min(0, Math.max(left, -child.getWidth())); } return ret; }
private int getViewWidthOrParam() { final LayoutParams layoutParams = view.getLayoutParams(); if (isSizeValid(view.getWidth())) { return view.getWidth(); } else if (layoutParams != null) { return getSizeForParam(layoutParams.width, false /*isHeight*/); } else { return PENDING_SIZE; } }
@Override public void animate(View view) { f = pickScale(); f2 = pickScale(); f3 = pickTranslation(view.getWidth(), f); f4 = pickTranslation(view.getHeight(), f); f5 = pickTranslation(view.getWidth(), f2); f6 = pickTranslation(view.getHeight(), f2); start(view, Image_Animation_Duration, f, f2, f3, f4, f5, f6); }
@Override protected void onTransform(View view, float position) { final float rotation = (position < 0 ? 30f : -30f) * Math.abs(position); ViewHelper.setTranslationX( view, getOffsetXForRotation(rotation, view.getWidth(), view.getHeight())); ViewHelper.setPivotX(view, view.getWidth() * 0.5f); ViewHelper.setPivotY(view, 0); ViewHelper.setRotationY(view, rotation); }
public static Bitmap takeScreenshot(View view) { if (view == null) return null; assert view.getWidth() > 0 && view.getHeight() > 0; Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), config); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; }
public void closeOpenedMenu() { state = STATE_CLOSE; if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) { mBaseX = -mContentView.getLeft(); mCloseScroller.startScroll(0, 0, mMenuView.getWidth(), 0, animDuration); } else { mBaseX = mMenuView.getRight(); mCloseScroller.startScroll(0, 0, mMenuView.getWidth(), 0, animDuration); } postInvalidate(); }
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { // Translate overlay and image float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize; int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight(); ViewHelper.setTranslationY( mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0)); ViewHelper.setTranslationY( mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0)); // Change alpha of overlay ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat( (flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); ViewHelper.setPivotX(mTitleView, 0); ViewHelper.setPivotY(mTitleView, 0); ViewHelper.setScaleX(mTitleView, scale); ViewHelper.setScaleY(mTitleView, scale); // Translate title text int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale); int titleTranslationY = maxTitleTranslationY - scrollY; ViewHelper.setTranslationY(mTitleView, titleTranslationY); // Translate FAB int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2; float fabTranslationY = ScrollUtils.getFloat( -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2, mActionBarSize - mFab.getHeight() / 2, maxFabTranslationY); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin, // which causes FAB's OnClickListener not working. FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams(); lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth(); lp.topMargin = (int) fabTranslationY; mFab.requestLayout(); } else { ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth()); ViewHelper.setTranslationY(mFab, fabTranslationY); } // Show/hide FAB if (fabTranslationY < mFlexibleSpaceShowFabOffset) { hideFab(); } else { showFab(); } }
private Animator createSegue(View from, View to, Flow.Direction direction) { boolean backward = direction == Flow.Direction.BACKWARD; int fromTranslation = backward ? from.getWidth() : -from.getWidth(); int toTranslation = backward ? -to.getWidth() : to.getWidth(); AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(from, View.TRANSLATION_X, fromTranslation)); set.play(ObjectAnimator.ofFloat(to, View.TRANSLATION_X, toTranslation, 0)); return set; }
public void updateProgress(int progress) { final int fairyEndX = mContentView.getWidth() / 2; final int fairyStartX = mImageViewFairy.getWidth() / 2; final int maxTravelDistance = Math.min(fairyEndX - fairyStartX, mContentView.getWidth() - mFairyContainer.getWidth()); final float translateX = maxTravelDistance * ((float) progress / 100); RelativeLayout.LayoutParams lp = (android.widget.RelativeLayout.LayoutParams) mFairyContainer.getLayoutParams(); lp.leftMargin = (int) translateX; mFairyContainer.setLayoutParams(lp); mProgressBar.setProgress(progress); }