List of usage examples for android.view View setTranslationX
public void setTranslationX(float translationX)
From source file:com.arlib.floatingsearchview.util.view.MenuView.java
/** * Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim) * * @param withAnim//from ww w . j a va 2s . co m */ public void showIfRoomItems(boolean withAnim) { if (mMenu == -1) return; cancelChildAnimListAndClear(); if (mMenuItems.isEmpty()) return; anims = new ArrayList<>(); for (int i = 0; i < getChildCount(); i++) { final View currentView = getChildAt(i); if (i < mActionItems.size()) { ImageView action = (ImageView) currentView; final MenuItem actionItem = mActionItems.get(i); action.setImageDrawable(Util.setIconColor(actionItem.getIcon(), mActionIconColor)); action.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mMenuCallback != null) mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem); } }); } //todo go over logic int animDuration = withAnim ? SHOW_IF_ROOM_ITEMS_ANIM_DURATION : 0; Interpolator interpolator = new DecelerateInterpolator(); //todo check logic if (i > mActionShowAlwaysItems.size() - 1) interpolator = new LinearInterpolator(); currentView.setClickable(true); anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { currentView.setTranslationX(0); } }).setInterpolator(interpolator).setDuration(animDuration).translationX(0).get()); anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { currentView.setScaleX(1.0f); } }).setInterpolator(interpolator).setDuration(animDuration).scaleX(1.0f).get()); anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { currentView.setScaleY(1.0f); } }).setInterpolator(interpolator).setDuration(animDuration).scaleY(1.0f).get()); anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { currentView.setAlpha(1.0f); } }).setInterpolator(interpolator).setDuration(animDuration).alpha(1.0f).get()); } AnimatorSet animSet = new AnimatorSet(); //temporary, from laziness if (!withAnim) animSet.setDuration(0); animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()])); animSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (mOnVisibleWidthChanged != null) mOnVisibleWidthChanged.onVisibleWidthChanged( (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0)); } }); animSet.start(); }
From source file:com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.java
protected void returnItemToPoolIfNeeded(FreeFlowItem freeflowItem) { View v = freeflowItem.view; v.setTranslationX(0); v.setTranslationY(0);//from w ww . ja v a2s.com v.setRotation(0); v.setScaleX(1f); v.setScaleY(1f); v.setAlpha(1); viewpool.returnViewToPool(v); }
From source file:com.doubleTwist.drawerlib.ADrawerLayout.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setDXYCompat(View v, int dx, int dy) { if (isRuntimePostGingerbread()) { v.setTranslationX(dx); v.setTranslationY(dy);//from www .ja va 2 s . c om } else { Rect bounds = mLayoutBounds.get(v); v.layout(bounds.left + dx, bounds.top + dy, bounds.right + dx, bounds.bottom + dy); // This method does not work so well // v.setAnimation(null); // TranslateAnimation ta = new TranslateAnimation(dx, dx, dy, dy); // ta.setFillAfter(true); // ta.setFillEnabled(true); // mLeft.startAnimation(ta); } }
From source file:com.upsideideas.zdrawerlayout.ADrawerLayout.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void setDXYCompat(View v, int dx, int dy) { if (isRuntimePostGingerbread()) { v.setTranslationX(dx); v.setTranslationY(dy);/*from ww w . j a v a2 s . c o m*/ } else { Rect bounds = mLayoutBounds.get(v); v.layout(bounds.left + dx, bounds.top + dy, bounds.right + dx, bounds.bottom + dy); // This method does not work so well // v.setAnimation(null); // TranslateAnimation ta = new TranslateAnimation(dx, dx, dy, dy); // ta.setFillAfter(true); // ta.setFillEnabled(true); // mLeft.startAnimation(ta); } }
From source file:com.geecko.QuickLyric.adapter.IntroScreenSlidePagerAdapter.java
@SuppressWarnings({ "deprecation", "ResourceAsColor" }) @Override//from ww w .j a v a 2s. c o m public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { View tutorialLayout = mActivity.findViewById(R.id.tutorial_layout); ArgbEvaluator evaluator = new ArgbEvaluator(); Object background = position < getCount() - 1 ? evaluator.evaluate(positionOffset, mActivity.getResources().getColor(colors[position]), mActivity.getResources().getColor(colors[position + 1])) : mActivity.getResources().getColor(colors[position]); tutorialLayout.setBackgroundColor((int) background); MainActivity.setNavBarColor(mActivity.getWindow(), mActivity.getTheme(), (int) evaluator.evaluate(0.5f, mActivity.getResources().getColor(R.color.action_dark), background)); MainActivity.setStatusBarColor(mActivity.getWindow(), mActivity.getTheme(), (int) evaluator.evaluate(0.5f, mActivity.getResources().getColor(R.color.action_dark), background)); View bigFab = tutorialLayout.findViewById(R.id.big_fab); View handImage = tutorialLayout.findViewById(R.id.musicid_demo_hand_image); View soundImage = tutorialLayout.findViewById(R.id.musicid_demo_sound_image); View redKey = tutorialLayout.findViewById(R.id.intro_4_red_key); View yellowKey = tutorialLayout.findViewById(R.id.intro_4_yellow_key); View gearA = tutorialLayout.findViewById(R.id.redGear); View gearB = tutorialLayout.findViewById(R.id.blueGear); BubblePopImageView tableImageView = (BubblePopImageView) tutorialLayout.findViewById(R.id.table); position = rightToLeft ? getCount() - 1 - position : position; if (rightToLeft && positionOffset > 0.0) { position -= 1; positionOffset = 1f - positionOffset; positionOffsetPixels = (int) (positionOffset * mPager.getWidth()); } switch (position) { case 0: if (tableImageView != null) { tableImageView.setProgress(positionOffset); tableImageView.setTranslationX((rightToLeft ? -1f : 1f) * (1f - positionOffset) * (tableImageView.getMeasuredWidth() / 3f)); } break; case 1: if (tableImageView != null) { tableImageView.setProgress(1f); tableImageView.setTranslationX((rightToLeft ? 0.15f : -0.4f) * positionOffsetPixels); } if (bigFab != null) { bigFab.setTranslationX( (rightToLeft ? -1f : 1f) * (1f - positionOffset) * (bigFab.getMeasuredWidth() / 3f)); if (mCurrentPage == 1 ^ rightToLeft) bigFab.setRotation(positionOffset * 360f); else bigFab.setRotation((1f - positionOffset) * 360f); } break; case 2: if (bigFab != null) ((View) bigFab.getParent()).setTranslationX((!rightToLeft ? -0.4f : 0.4f) * positionOffsetPixels); if (soundImage != null && handImage != null) { soundImage.setTranslationX(300f - 300f * positionOffset); handImage.setTranslationX(-400f + 400f * positionOffset); } break; case 3: if (redKey != null && yellowKey != null) { if (redKey.getMeasuredHeight() < redKey.getResources().getDimensionPixelSize(R.dimen.dp) * 15) { redKey.setVisibility(View.INVISIBLE); yellowKey.setVisibility(View.INVISIBLE); break; } else { redKey.setVisibility(View.VISIBLE); yellowKey.setVisibility(View.VISIBLE); } redKey.setTranslationY(330f * (1 - positionOffset)); yellowKey.setTranslationY(290f * Math.min(1.3f * (1 - positionOffset), 1.0f)); yellowKey.setTranslationX(105f * Math.min(1.3f * (1 - positionOffset), 1.0f)); } if (3 == count - 2 && gearA != null && gearB != null) { gearA.setRotation(-180f * positionOffset); gearB.setRotation(180f * positionOffset); } break; case 4: if (gearA != null && gearB != null) { gearA.setRotation(-180f * positionOffset); gearB.setRotation(180f * positionOffset); } break; } }
From source file:com.oguzbabaoglu.cardpager.CardPager.java
/** * Transforms the top and bottom pages with changing scroll. * If top page is moving to the right side (virtualPos > 0) * we need to counteract the scroll by twice as much. * * @param view child view//from w w w.ja va 2 s. c o m * @param position position with offset */ protected void transformPage(View view, float position) { int pageWidth = view.getWidth(); if (position < -1) { // This page is off-screen view.setAlpha(0); } else if (position <= 0) { view.setAlpha(1); // Counteract the default slide transition if (virtualPos > 0) { view.setTranslationX(pageWidth * -position * 2); } else { view.setTranslationX(0); } // Scale the page down (between MIN_SCALE and 1) float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); } else if (position <= 1) { // Fade the page out. view.setAlpha(1 - position); // Counteract the default slide transition view.setTranslationX(pageWidth * -position); // Scale the page down (between MIN_SCALE and 1) float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); } else { // This page is off-screen view.setAlpha(0); } }
From source file:com.tmall.wireless.tangram.MVHelper.java
protected void renderLayout(BaseCell cell, View view) { if (cell.style != null) { ViewGroup.LayoutParams lp = view.getLayoutParams(); if (lp == null || !(lp instanceof VirtualLayoutManager.LayoutParams)) { lp = new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); view.setLayoutParams(lp);//from w w w. j a va 2s . co m } if (lp instanceof VirtualLayoutManager.LayoutParams) { VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) lp; if (cell.style.height >= 0) { params.storeOriginHeight(); params.height = cell.style.height; } else { params.restoreOriginHeight(); } if (cell.style.width >= 0) { params.storeOriginWidth(); params.width = cell.style.width; } else { params.restoreOriginWidth(); } params.mAspectRatio = cell.style.aspectRatio; } else { if (cell.style.height >= 0) { lp.height = cell.style.height; } if (cell.style.width >= 0) { lp.width = cell.style.width; } } if (lp instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) lp; layoutParams.topMargin = cell.style.margin[MARGIN_TOP_INDEX]; layoutParams.leftMargin = cell.style.margin[MARGIN_LEFT_INDEX]; layoutParams.bottomMargin = cell.style.margin[MARGIN_BOTTOM_INDEX]; layoutParams.rightMargin = cell.style.margin[MARGIN_RIGHT_INDEX]; } // reset translation animation before reused view.setTranslationX(0); view.setTranslationY(0); } }
From source file:uk.ac.horizon.artcodes.ui.MarkerHistoryViewController.java
public void update(List<MarkerImage> incomingMarkerImages, final Action currentOrFutureAction) { if (currentOrFutureAction == null || incomingMarkerImages == null || incomingMarkerImages.isEmpty()) { this.existingMarkerImages.clear(); this.existingAction = null; incomingMarkerImages = new ArrayList<>(); }//from www .ja v a 2s . c o m final List<MarkerImage> markerImages = incomingMarkerImages; final Action.Match existingMatchType = existingAction != null ? existingAction.getMatch() : Action.Match.any; final Action.Match currentMatchType = currentOrFutureAction != null ? currentOrFutureAction.getMatch() : Action.Match.any; final int n = markerImages.size(); final int viewSizePX = (int) (VIEW_WIDTH_DP * displayDensity); final int separatorWidthPX = (int) (SEPARATOR_WIDTH_DP * displayDensity); final int startX = (int) (relativeLayout.getWidth() / 2 - (n * viewSizePX / 2f) - ((n - 1) * separatorWidthPX / 2f)); final int finalTranslationY = relativeLayout.getHeight() - viewSizePX - (int) (BOTTOM_MARGIN_DP * displayDensity); final int finalTranslationYForSeparator = finalTranslationY + (int) (12.5 * displayDensity); this.uiHandler.post(new Runnable() { @Override public void run() { // animate removal of views not in markerImages (and unneeded separators/placeholders) // TODO: instead of creating/destroying separators/placeholders they should be reused. // Remove placeholders List<Map.Entry<Integer, View>> missingToRemove = new ArrayList<>(); for (Map.Entry<Integer, View> entry : missingViewsByPosition.entrySet()) { if (entry.getKey() >= markerImages.size() - 1) { missingToRemove.add(entry); } } for (Map.Entry<Integer, View> entry : missingToRemove) { final View view = entry.getValue(); animateRemoval(view); missingViewsByPosition.remove(entry.getKey()); } // Remove separators List<Map.Entry<Integer, View>> separatorsToRemove = new ArrayList<>(); if (currentOrFutureAction != null && existingMatchType == currentMatchType) { for (Map.Entry<Integer, View> entry : seperatorViewsByPosition.entrySet()) { if (entry.getKey() >= markerImages.size() - 2) { separatorsToRemove.add(entry); } } } else { separatorsToRemove.addAll(seperatorViewsByPosition.entrySet()); } for (Map.Entry<Integer, View> entry : separatorsToRemove) { final View view = entry.getValue(); animateRemoval(view); seperatorViewsByPosition.remove(entry.getKey()); } // Remove marker images List<Map.Entry<MarkerImage, View>> toRemove = new ArrayList<>(); for (Map.Entry<MarkerImage, View> entry : displayedViews.entrySet()) { if (!markerImages.contains(entry.getKey())) { toRemove.add(entry); } } for (Map.Entry<MarkerImage, View> entry : toRemove) { final View view = entry.getValue(); animateRemoval(view); displayedViews.remove(entry.getKey()); } // Add or re-position views of images in markerImages (and separators/placeholders) int count = 0; for (MarkerImage markerImage : markerImages) { if (markerImage != null) { // add/re-position marker image final View missingView = missingViewsByPosition.get(count); if (missingView != null) { animateRemoval(missingView); missingViewsByPosition.remove(count); } View markerImageView = displayedViews.get(markerImage); if (markerImageView == null) { markerImageView = LayoutInflater.from(context).inflate(R.layout.marker_thumbnail, null); final ImageView imageView = (ImageView) markerImageView .findViewById(R.id.marker_thumbnail_image); if (imageView == null) { continue; } imageView.setImageBitmap(markerImage.image); } // Note: Translation ignores scale, and scale scales around the centre of the view. int finalTranslationX = startX + count * (viewSizePX + separatorWidthPX); if (markerImage.newDetection) { final int initialImageWidthPX = (int) (relativeLayout.getWidth() * markerImage.width); final int initialImageHeightPX = (int) (relativeLayout.getHeight() * markerImage.height); final float initialScale = (Math.max(initialImageWidthPX, initialImageHeightPX) / displayDensity) / IMAGE_WIDTH_DP; final int initialImageXCenter = (int) (relativeLayout.getWidth() * markerImage.x + initialImageWidthPX / 2); final int initialImageYCenter = (int) (relativeLayout.getHeight() * markerImage.y + initialImageHeightPX / 2); final int initialViewX = initialImageXCenter - viewSizePX / 2; final int initialViewY = initialImageYCenter - viewSizePX / 2; markerImageView.setTranslationX(initialViewX); markerImageView.setTranslationY(initialViewY); markerImageView.setScaleX(initialScale); markerImageView.setScaleY(initialScale); markerImageView.setAlpha(0f); if (!displayedViews.containsKey(markerImage)) { relativeLayout.addView(markerImageView); displayedViews.put(markerImage, markerImageView); } animateEnterOrMove(markerImageView, finalTranslationX, finalTranslationY, 1); } else { if (!displayedViews.containsKey(markerImage)) { markerImageView.setScaleX(1); markerImageView.setScaleY(1); markerImageView.setTranslationX(finalTranslationX); markerImageView.setTranslationY(finalTranslationY); markerImageView.setAlpha(0f); relativeLayout.addView(markerImageView); displayedViews.put(markerImage, markerImageView); } animateEnterOrMove(markerImageView, finalTranslationX, finalTranslationY, 1); } } else { // add/move placeholder for missing marker View view = missingViewsByPosition.get(count); final int finalTranslationX = startX + count * (viewSizePX + (int) (SEPARATOR_WIDTH_DP * displayDensity)); if (view == null) { view = createMarkerPlaceholder(); view.setTranslationX(finalTranslationX); view.setTranslationY(finalTranslationY); view.setAlpha(0f); missingViewsByPosition.put(count, view); relativeLayout.addView(view); } animateEnterOrMove(view, finalTranslationX, finalTranslationY); } // add/move separator if (count < markerImages.size() - 1) { View view = seperatorViewsByPosition.get(count); final int finalTranslationX = startX + (count + 1) * (viewSizePX + (int) (SEPARATOR_WIDTH_DP * displayDensity)) - (int) (SEPARATOR_WIDTH_DP * displayDensity); if (view == null) { if (currentMatchType == Action.Match.all) { view = createGroupSeparator(); } else { view = createSequenceSeparator(); } view.setTranslationX(finalTranslationX); view.setTranslationY(finalTranslationYForSeparator); view.setAlpha(0f); seperatorViewsByPosition.put(count, view); relativeLayout.addView(view); } animateEnterOrMove(view, finalTranslationX, finalTranslationYForSeparator); } ++count; } } }); this.existingMarkerImages = markerImages; this.existingAction = currentOrFutureAction; }
From source file:info.bartowski.easteregg.LLand.java
private void step(long t_ms, long dt_ms) { t = t_ms / 1000f; // seconds dt = dt_ms / 1000f;//from w w w . j a va 2 s. c om if (DEBUG) { t *= DEBUG_SPEED_MULTIPLIER; dt *= DEBUG_SPEED_MULTIPLIER; } // 1. Move all objects and update bounds final int N = getChildCount(); int i = 0; for (; i < N; i++) { final View v = getChildAt(i); if (v instanceof GameView) { ((GameView) v).step(t_ms, dt_ms, t, dt); } } // 2. Check for altitude if (mPlaying && mDroid.below(mHeight)) { if (DEBUG_IDDQD) { poke(); } else { L("player hit the floor"); stop(); } } // 3. Check for obstacles boolean passedBarrier = false; for (int j = mObstaclesInPlay.size(); j-- > 0;) { final Obstacle ob = mObstaclesInPlay.get(j); if (mPlaying && ob.intersects(mDroid) && !DEBUG_IDDQD) { L("player hit an obstacle"); stop(); } else if (ob.cleared(mDroid)) { if (ob instanceof Stem) passedBarrier = true; mObstaclesInPlay.remove(j); } } if (mPlaying && passedBarrier) { addScore(1); } // 4. Handle edge of screen // Walk backwards to make sure removal is safe while (i-- > 0) { final View v = getChildAt(i); if (v instanceof Obstacle) { if (v.getTranslationX() + v.getWidth() < 0) { removeViewAt(i); } } else if (v instanceof Scenery) { final Scenery s = (Scenery) v; if (v.getTranslationX() + s.w < 0) { v.setTranslationX(getWidth()); } } } // 3. Time for more obstacles! if (mPlaying && (t - mLastPipeTime) > PARAMS.OBSTACLE_PERIOD) { mLastPipeTime = t; final int obstacley = (int) (Math.random() * (mHeight - 2 * PARAMS.OBSTACLE_MIN - PARAMS.OBSTACLE_GAP)) + PARAMS.OBSTACLE_MIN; final int inset = (PARAMS.OBSTACLE_WIDTH - PARAMS.OBSTACLE_STEM_WIDTH) / 2; final int yinset = PARAMS.OBSTACLE_WIDTH / 2; final int d1 = irand(0, 250); final Obstacle s1 = new Stem(getContext(), obstacley - yinset, false); addView(s1, new LayoutParams(PARAMS.OBSTACLE_STEM_WIDTH, (int) s1.h, Gravity.TOP | Gravity.LEFT)); s1.setTranslationX(mWidth + inset); s1.setTranslationY(-s1.h - yinset); ViewCompat.setTranslationZ(s1, PARAMS.OBSTACLE_Z * 0.75f); s1.animate().translationY(0).setStartDelay(d1).setDuration(250); mObstaclesInPlay.add(s1); final Obstacle p1 = new Pop(getContext(), PARAMS.OBSTACLE_WIDTH); addView(p1, new LayoutParams(PARAMS.OBSTACLE_WIDTH, PARAMS.OBSTACLE_WIDTH, Gravity.TOP | Gravity.LEFT)); p1.setTranslationX(mWidth); p1.setTranslationY(-PARAMS.OBSTACLE_WIDTH); ViewCompat.setTranslationZ(p1, PARAMS.OBSTACLE_Z); p1.setScaleX(0.25f); p1.setScaleY(0.25f); p1.animate().translationY(s1.h - inset).scaleX(1f).scaleY(1f).setStartDelay(d1).setDuration(250); mObstaclesInPlay.add(p1); final int d2 = irand(0, 250); final Obstacle s2 = new Stem(getContext(), mHeight - obstacley - PARAMS.OBSTACLE_GAP - yinset, true); addView(s2, new LayoutParams(PARAMS.OBSTACLE_STEM_WIDTH, (int) s2.h, Gravity.TOP | Gravity.LEFT)); s2.setTranslationX(mWidth + inset); s2.setTranslationY(mHeight + yinset); ViewCompat.setTranslationZ(s2, PARAMS.OBSTACLE_Z * 0.75f); s2.animate().translationY(mHeight - s2.h).setStartDelay(d2).setDuration(400); mObstaclesInPlay.add(s2); final Obstacle p2 = new Pop(getContext(), PARAMS.OBSTACLE_WIDTH); addView(p2, new LayoutParams(PARAMS.OBSTACLE_WIDTH, PARAMS.OBSTACLE_WIDTH, Gravity.TOP | Gravity.LEFT)); p2.setTranslationX(mWidth); p2.setTranslationY(mHeight); ViewCompat.setTranslationZ(p2, PARAMS.OBSTACLE_Z); p2.setScaleX(0.25f); p2.setScaleY(0.25f); p2.animate().translationY(mHeight - s2.h - yinset).scaleX(1f).scaleY(1f).setStartDelay(d2) .setDuration(400); mObstaclesInPlay.add(p2); } if (DEBUG_DRAW) invalidate(); }
From source file:com.tmall.wireless.tangram3.MVHelper.java
protected void renderLayout(BaseCell cell, View view) { if (cell.style != null) { ViewGroup.LayoutParams lp = view.getLayoutParams(); if (lp == null || !(lp instanceof VirtualLayoutManager.LayoutParams)) { if (lp == null) { lp = new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } else { lp = new VirtualLayoutManager.LayoutParams(lp.width, lp.height); }/*from w w w .j a va 2s . c o m*/ view.setLayoutParams(lp); } if (lp instanceof VirtualLayoutManager.LayoutParams) { VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) lp; if (cell.style.height >= 0) { params.storeOriginHeight(); params.height = cell.style.height; } else { params.restoreOriginHeight(); } if (cell.style.width >= 0) { params.storeOriginWidth(); params.width = cell.style.width; } else { params.restoreOriginWidth(); } params.mAspectRatio = cell.style.aspectRatio; params.zIndex = cell.style.zIndex; if (params.zIndex == 0) { if (cell.parent != null && cell.parent.style != null) { params.zIndex = cell.parent.style.zIndex; } } if (VERSION.SDK_INT >= 21) { view.setZ(params.zIndex); } } else { if (cell.style.height >= 0) { lp.height = cell.style.height; } if (cell.style.width >= 0) { lp.width = cell.style.width; } } if (lp instanceof ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) lp; layoutParams.topMargin = cell.style.margin[MARGIN_TOP_INDEX]; layoutParams.leftMargin = cell.style.margin[MARGIN_LEFT_INDEX]; layoutParams.bottomMargin = cell.style.margin[MARGIN_BOTTOM_INDEX]; layoutParams.rightMargin = cell.style.margin[MARGIN_RIGHT_INDEX]; } // reset translation animation before reused view.setTranslationX(0); view.setTranslationY(0); } }