Java Code Examples for android.view.View#getX()
The following examples show how to use
android.view.View#getX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimationHelper.java From FABRevealMenu-master with Apache License 2.0 | 6 votes |
public void moveFab(View fabView, View revealView, Direction direction, boolean isReturning, final AnimationListener listener) { float scaleFactor = isReturning ? -FAB_SCALE_FACTOR : FAB_SCALE_FACTOR; float alpha = isReturning ? 1.0f : 1.0f; float endX; float endY; if (!isReturning) { Point anchorPoint = viewHelper.updateFabAnchor(fabView); anchorX = anchorPoint.x; anchorY = anchorPoint.y; endX = revealView.getX() + centerX; endY = revealView.getY() + centerY; } else { endX = anchorX; endY = anchorY; } //move by arc animation startArcAnim(fabView, endX, endY, FAB_ARC_DEGREES, getArcSide(direction), FAB_ANIM_DURATION, fabAnimInterpolator, listener); //scale fab fabView.animate().scaleXBy(scaleFactor).scaleYBy(scaleFactor).alpha(alpha).setDuration(FAB_ANIM_DURATION).start(); }
Example 2
Source File: TurnLayoutManager.java From turn-layout-manager with Apache License 2.0 | 6 votes |
/** * Given that the orientation is {@link Orientation#HORIZONTAL}, apply rotation if enabled. */ private void setChildRotationHorizontal(@Gravity int gravity, View child, int radius, Point center) { if (!rotate) { child.setRotation(0); return; } boolean childPastCenter = (child.getX() + child.getWidth() / 2) > center.x; float directionMult; if (gravity == Gravity.END) { directionMult = childPastCenter ? 1 : -1; } else { directionMult = childPastCenter ? -1 : 1; } final float opposite = Math.abs(child.getX() + child.getWidth() / 2.0f - center.x); child.setRotation((float) (directionMult * Math.toDegrees(Math.asin(opposite / radius)))); }
Example 3
Source File: OnSwipeTouchListener.java From evercam-android with GNU Affero General Public License v3.0 | 6 votes |
private void onActionZoom(View view) { int originalWidth = view.getWidth(); int originalHeight = view.getHeight(); long currentTime = System.nanoTime(); if (time != 0 && (currentTime - time) > 10000000) { int leftOffset = (int) (originalWidth - (originalWidth * scaleListener.scaleFactor)); int topOffset = (int) (originalHeight - (originalHeight * scaleListener.scaleFactor)); Log.e(TAG, "Offset: " + leftOffset + "," + topOffset); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams(); layoutParams.setMargins(leftOffset, topOffset, leftOffset, topOffset); view.setLayoutParams(layoutParams); //Avoid showing the blanks if (view.getX() >= 0) { view.setX(0); } if (view.getX() + view.getWidth() <= getScreenWidth()) { view.setX(getScreenWidth() - view.getWidth()); } } time = System.nanoTime(); }
Example 4
Source File: PictureTagLayout.java From Android-PictureTagView with Artistic License 2.0 | 6 votes |
private boolean hasView(int x,int y){ //循环获取子view,判断xy是否在子view上,即判断是否按住了子view for(int index = 0; index < this.getChildCount(); index ++){ View view = this.getChildAt(index); int left = (int) view.getX(); int top = (int) view.getY(); int right = view.getRight(); int bottom = view.getBottom(); Rect rect = new Rect(left, top, right, bottom); boolean contains = rect.contains(x, y); //如果是与子view重叠则返回真,表示已经有了view不需要添加新view了 if(contains){ touchView = view; touchView.bringToFront(); return true; } } touchView = null; return false; }
Example 5
Source File: SelectRecyclerView.java From PlayTogether with Apache License 2.0 | 6 votes |
/** * 设置可视recyclerView可视item的属性(字体大小、透明度) */ public void setItemStyle() { int firstVisiblePos = mLayoutManager.findFirstVisibleItemPosition(); int lastVisiblePos = mLayoutManager.findLastVisibleItemPosition(); int itemHeight = getMeasuredHeight() / DISPLAY_ITEM_COUNT; for (int i = firstVisiblePos; i <= lastVisiblePos; i++) { View view = mLayoutManager.findViewByPosition(i); int x = (int) view.getX(); int y = (int) view.getY(); //itemCenter:item的中点,相对于parent的y距离 int itemCenter = y + itemHeight / 2; if (itemCenter < 0) itemCenter = 0; //distanceToCenter:item的中点距离parent的y距离 int distanceToCenter = Math.abs(getMeasuredHeight() / 2 - itemCenter); // Logger.e("toCenter:" + distanceToCenter + ",testSize:" + (float) (mMaxTextSize - // mTextSizeScale * distanceToCenter)); TextView textview = (TextView) view.findViewById(R.id.tv); //距离中点最近的时候透明度最大,字体也最大 //设置textview字体大小随着距离中点距离的改变而改变 textview.setTextSize((float) (mMaxTextSize - mTextSizeScale * distanceToCenter)); //设置textview透明度随着距离中点距离的改变而改变 textview.setAlpha((float) (mMaxTextAlpha - mTextAlphaScale * distanceToCenter)); } }
Example 6
Source File: CallActivity.java From linphone-android with GNU General Public License v3.0 | 6 votes |
private boolean moveLocalPreview(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: mPreviewX = view.getX() - motionEvent.getRawX(); mPreviewY = view.getY() - motionEvent.getRawY(); break; case MotionEvent.ACTION_MOVE: view.animate() .x(motionEvent.getRawX() + mPreviewX) .y(motionEvent.getRawY() + mPreviewY) .setDuration(0) .start(); break; default: return false; } return true; }
Example 7
Source File: LayoutUpdateAnimation.java From react-native-GPay with MIT License | 6 votes |
@Override @Nullable Animation createAnimationImpl(View view, int x, int y, int width, int height) { boolean animateLocation = view.getX() != x || view.getY() != y; boolean animateSize = view.getWidth() != width || view.getHeight() != height; if (!animateLocation && !animateSize) { return null; } else if (animateLocation && !animateSize && USE_TRANSLATE_ANIMATION) { // Use GPU-accelerated animation, however we loose the ability to resume interrupted // animation where it was left off. We may be able to listen to animation interruption // and set the layout manually in this case, so that next animation kicks off smoothly. return new TranslateAnimation(view.getX() - x, 0, view.getY() - y, 0); } else { // Animation is sub-optimal for perf, but scale transformation can't be use in this case. return new PositionAndSizeAnimation(view, x, y, width, height); } }
Example 8
Source File: PercentageViewBehavior.java From simple-view-behavior with MIT License | 5 votes |
/** * Update the child view from the dependency states * * @param child child view * @param dependency dependency view */ void updateView(V child, View dependency) { float percent = 0; float start = 0; float current = 0; float end = UNSPECIFIED_INT; switch (mDependType) { case DEPEND_TYPE_WIDTH: start = mDependStartWidth; current = dependency.getWidth(); end = mDependTarget; break; case DEPEND_TYPE_HEIGHT: start = mDependStartHeight; current = dependency.getHeight(); end = mDependTarget; break; case DEPEND_TYPE_X: start = mDependStartX; current = dependency.getX(); end = mDependTarget; break; case DEPEND_TYPE_Y: start = mDependStartY; current = dependency.getY(); end = mDependTarget; break; } // need to define target value according to the depend type, if not then skip if (end != UNSPECIFIED_INT) { percent = Math.abs(current - start) / Math.abs(end - start); } updateViewWithPercent(child, percent > 1 ? 1 : percent); }
Example 9
Source File: CameraView.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
/** * 根据raw坐标转换成屏幕中所在的坐标 * @param pointF * @return */ private PointF transPointF(PointF pointF, View view) { pointF.x -= view.getX(); pointF.y -= view.getY(); ViewParent parent = view.getParent(); if (parent instanceof View) { return transPointF(pointF, (View) parent); } else { return pointF; } }
Example 10
Source File: DragItem.java From DragListView with Apache License 2.0 | 5 votes |
void startDrag(View startFromView, float touchX, float touchY) { show(); mRealDragView = startFromView; onBindDragView(startFromView, mDragView); onMeasureDragView(startFromView, mDragView); onStartDragAnimation(mDragView); float startX = startFromView.getX() - (mDragView.getMeasuredWidth() - startFromView.getMeasuredWidth()) / 2f + mDragView .getMeasuredWidth() / 2f; float startY = startFromView.getY() - (mDragView.getMeasuredHeight() - startFromView.getMeasuredHeight()) / 2f + mDragView .getMeasuredHeight() / 2f; if (mSnapToTouch) { mPosTouchDx = 0; mPosTouchDy = 0; setPosition(touchX, touchY); setAnimationDx(startX - touchX); setAnimationDY(startY - touchY); PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("AnimationDx", mAnimationDx, 0); PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("AnimationDY", mAnimationDy, 0); ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(this, pvhX, pvhY); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(ANIMATION_DURATION); anim.start(); } else { mPosTouchDx = startX - touchX; mPosTouchDy = startY - touchY; setPosition(touchX, touchY); } }
Example 11
Source File: PercentageViewBehavior.java From simple-view-behavior with MIT License | 5 votes |
/** * Call this before making any changes to the view to setup values * * @param parent coordinator layout as parent * @param child view that will move when dependency changed * @param dependency dependency view */ void prepare(CoordinatorLayout parent, V child, View dependency) { mDependStartX = (int) dependency.getX(); mDependStartY = (int) dependency.getY(); mDependStartWidth = dependency.getWidth(); mDependStartHeight = dependency.getHeight(); isPrepared = true; }
Example 12
Source File: RecyclerViewAttacher.java From ScrollingPagerIndicator with Apache License 2.0 | 5 votes |
private void updateCurrentOffset() { final View firstView = findFirstVisibleView(); if (firstView == null) { return; } int position = recyclerView.getChildAdapterPosition(firstView); if (position == RecyclerView.NO_POSITION) { return; } final int itemCount = attachedAdapter.getItemCount(); // In case there is an infinite pager if (position >= itemCount && itemCount != 0) { position = position % itemCount; } float offset; if (layoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) { offset = (getCurrentFrameLeft() - firstView.getX()) / firstView.getMeasuredWidth(); } else { offset = (getCurrentFrameBottom() - firstView.getY()) / firstView.getMeasuredHeight(); } if (offset >= 0 && offset <= 1 && position < itemCount) { indicator.onPageScrolled(position, offset); } }
Example 13
Source File: RxAnimations.java From RxAnimations with Apache License 2.0 | 5 votes |
public static Completable slideHorizontal(final View view, final int duration, final int xOffset) { final float endingX = view.getX() + xOffset; return animate(view, new AccelerateDecelerateInterpolator()) .duration(duration) .translateBy(xOffset, 0) .onAnimationCancel(v -> v.setX(endingX)) .schedule(false); }
Example 14
Source File: RhythmLayout.java From MousePaint with MIT License | 5 votes |
public int getFirstVisibleItemPosition() { if (mLinearLayout == null) { return 0; } int size = mLinearLayout.getChildCount(); for (int i = 0; i < size; i++) { View view = mLinearLayout.getChildAt(i); if (getScrollX() < view.getX() + mItemWidth / 2.0F) return i; } return 0; }
Example 15
Source File: Utils.java From recycler-fast-scroll with Apache License 2.0 | 5 votes |
public static float getViewRawX(View view) { int[] location = new int[2]; location[0] = (int) view.getX(); location[1] = 0; ((View)view.getParent()).getLocationInWindow(location); return location[0]; }
Example 16
Source File: SwitchThemeAnimView.java From DanDanPlayForAndroid with MIT License | 5 votes |
/** * 获取view在屏幕中的绝对x坐标 */ private static float getAbsoluteX(View view) { float x = view.getX(); ViewParent parent = view.getParent(); if (parent instanceof View) { x += getAbsoluteX((View) parent); } return x; }
Example 17
Source File: CallFragment.java From owt-client-android with Apache License 2.0 | 5 votes |
@Override public boolean onTouch(View v, MotionEvent event) { if (v.getId() == R.id.small_renderer) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: dX = v.getX() - event.getRawX(); dY = v.getY() - event.getRawY(); break; case MotionEvent.ACTION_MOVE: v.animate() .x(event.getRawX() + dX) .y(event.getRawY() + dY) .setDuration(0) .start(); break; case MotionEvent.ACTION_UP: v.animate() .x(event.getRawX() + dX >= event.getRawY() + dY ? event.getRawX() + dX : 0) .y(event.getRawX() + dX >= event.getRawY() + dY ? 0 : event.getRawY() + dY) .setDuration(10) .start(); break; } } return true; }
Example 18
Source File: PositionAnimationPairPropertyUpdater.java From react-native-GPay with MIT License | 4 votes |
@Override protected void getProperty(View view, float[] returnValues) { returnValues[0] = view.getX() + 0.5f * view.getWidth(); returnValues[1] = view.getY() + 0.5f * view.getHeight(); }
Example 19
Source File: ViewHelper.java From KJFrameForAndroid with Apache License 2.0 | 4 votes |
static float getX(View view) { return view.getX(); }
Example 20
Source File: ViewHelper.java From Mover with Apache License 2.0 | 4 votes |
static float getX(View view) { return view.getX(); }