android.view.View#setY ( )源码实例Demo

下面列出了android.view.View#setY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public void setChildPositionsFromCassowaryModel() {
    long timeBeforeSolve = System.nanoTime();
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
        View child = getChildAt(i);
        if (child.getVisibility() != GONE) {

            int childId = child.getId();

            Node node = getNodeById(childId);

            int x = (int) node.getLeft().value() + getPaddingLeft();
            int y = (int) node.getTop().value() + getPaddingTop();

            child.setX(x);
            child.setY(y);

        }
    }
    log("setChildPositionsFromCassowaryModel - took " + TimerUtil.since(timeBeforeSolve));
}
 
源代码2 项目: debugkit   文件: DevToolFragment.java
private boolean onTouch(View v, MotionEvent event) {

        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                dX = v.getX() - event.getRawX();
                dY = v.getY() - event.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                v.setX(event.getRawX() + dX);
                v.setY(event.getRawY() + dY);
                break;
            case MotionEvent.ACTION_UP:
                break;
            default:
                return false;
        }

        return true;
    }
 
源代码3 项目: CloudReader   文件: Instrument.java
public void slidingToY(View view ,float y){
    if(view == null){
        return;
    }
    view.clearAnimation();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        view.setY(y);
    }else{
        ViewHelper.setY(view, y);
    }
}
 
private void anchorViews(int reference) {
    // move all views that are anchored to the bottomsheet
    for (int i = 0, size = anchoredViews.size(); i < size; i++) {
        View view = anchoredViews.get(i);
        CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
        view.setY(reference - lp.bottomMargin - lp.height);
    }

    // set the padding on the map
    if (map != null) {
        map.setPadding(0, 0, 0, mParentHeight - reference);
    }
}
 
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
  /**
   * collapsedY and achorPointY are calculated every time looking for
   * flexibility, in case that dependency's height, child's height or {@link BottomSheetBehaviorGoogleMapsLike#getPeekHeight()}'s
   * value changes throught the time, I mean, you can have a {@link android.widget.ImageView}
   * using images with different sizes and you don't want to resize them or so
   */
  if (mBottomSheetBehaviorRef == null || mBottomSheetBehaviorRef.get() == null)
    getBottomSheetBehavior(parent);
  /**
   * mCollapsedY: Y position in where backdrop get hidden behind dependency.
   * {@link BottomSheetBehaviorGoogleMapsLike#getPeekHeight()} and collapsedY are the same point on screen.
   */
  int collapsedY = dependency.getHeight() - mBottomSheetBehaviorRef.get().getPeekHeight();
  /**
   * achorPointY: with top being Y=0, achorPointY defines the point in Y where could
   * happen 2 things:
   * The backdrop should be moved behind dependency view (when {@link #mCurrentChildY} got
   * positive values) or the dependency view overlaps the backdrop (when
   * {@link #mCurrentChildY} got negative values)
   */
  int achorPointY = child.getHeight();
  /**
   * lastCurrentChildY: Just to know if we need to return true or false at the end of this
   * method.
   */
  int lastCurrentChildY = mCurrentChildY;

  if((mCurrentChildY = (int) ((dependency.getY()-achorPointY) * collapsedY / (collapsedY-achorPointY))) <= 0)
    child.setY(mCurrentChildY = 0);
  else
    child.setY(mCurrentChildY);
  return (lastCurrentChildY == mCurrentChildY);
}
 
源代码6 项目: AndroidFloatLabel   文件: FloatLabel.java
@Override
public void onDisplayLabel(View label) {
    final float offset = label.getHeight() / 2;
    final float currentY = label.getY();
    if (currentY != offset) {
        label.setY(offset);
    }
    label.animate().alpha(1).y(0);
}
 
源代码7 项目: Indic-Keyboard   文件: MoreKeysKeyboardView.java
@Override
public void showMoreKeysPanel(final View parentView, final Controller controller,
        final int pointX, final int pointY, final KeyboardActionListener listener) {
    mController = controller;
    mListener = listener;
    final View container = getContainerView();
    // The coordinates of panel's left-top corner in parentView's coordinate system.
    // We need to consider background drawable paddings.
    final int x = pointX - getDefaultCoordX() - container.getPaddingLeft() - getPaddingLeft();
    final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
            + getPaddingBottom();

    parentView.getLocationInWindow(mCoordinates);
    // Ensure the horizontal position of the panel does not extend past the parentView edges.
    final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
    final int panelX = Math.max(0, Math.min(maxX, x)) + CoordinateUtils.x(mCoordinates);
    final int panelY = y + CoordinateUtils.y(mCoordinates);
    container.setX(panelX);
    container.setY(panelY);

    mOriginX = x + container.getPaddingLeft();
    mOriginY = y + container.getPaddingTop();
    controller.onShowMoreKeysPanel(this);
    final MoreKeysKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
    if (accessibilityDelegate != null
            && AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
        accessibilityDelegate.onShowMoreKeysKeyboard();
    }
}
 
源代码8 项目: Trebuchet   文件: Folder.java
private void prepareFakeFolderIcon() {
    mFolderIcon.destroyDrawingCache();
    mFolderIcon.buildDrawingCache(true);

    Bitmap fakeFolderIcon = Bitmap.createBitmap(mFolderIcon.getDrawingCache());
    View fakeFolderIconView = mLauncher.findViewById(R.id.reveal_fake_folder_icon);
    FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams)
            fakeFolderIconView.getLayoutParams();

    // Get globalVisibleRect of the folderIcon. getWidth and getHeight are inaccurate for
    // hotseat icons
    Rect rect = new Rect();
    mFolderIcon.getGlobalVisibleRect(rect);

    flp.height = rect.height();
    flp.width = rect.width();

    fakeFolderIconView.setLayoutParams(flp);

    int [] folderIconXY = new int[2];
    mFolderIcon.getLocationOnScreen(folderIconXY);
    fakeFolderIconView.setX(folderIconXY[0]);
    fakeFolderIconView.setY(folderIconXY[1]);

    fakeFolderIconView.setBackground(new BitmapDrawable(null, fakeFolderIcon));
    fakeFolderIconView.setVisibility(View.INVISIBLE);
}
 
源代码9 项目: Beedio   文件: BrowserWindow.java
@Override
public boolean onLongClick(View v) {
    final WebView.HitTestResult hit = page.getHitTestResult();
    if (hit.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
        if (hit.getExtra() != null) {
            View point = new View(getActivity());
            point.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams
                    .WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            if (view != null) {
                ((ViewGroup) view).addView(point);
            }
            point.getLayoutParams().height = 10;
            point.getLayoutParams().width = 10;
            point.setX(page.getClickX());
            point.setY(page.getClickY());
            PopupMenu menu = new PopupMenu(getActivity(), point);
            menu.getMenu().add("Open in new window");
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    getLMvdActivity().getBrowserManager().newWindow(hit.getExtra());
                    return true;
                }
            });
            menu.show();
        }
    }
    return true;
}
 
源代码10 项目: xDrip   文件: XDripDreamService.java
/**
 * Bouncing view setup: random placement, random velocity.
 */
private void setupView(View v) {
    final PointF p = new PointF();
    final float a = (float) (Math.random() * 360);
    p.x = mMaxSpeed * (float) (Math.cos(a));
    p.y = mMaxSpeed * (float) (Math.sin(a));
    v.setTag(p);
    v.setX((float) (Math.random() * (mWidth - Math.max(v.getWidth(), v.getHeight()))));
    v.setY((float) (Math.random() * (mHeight - Math.max(v.getHeight(), v.getWidth()))));
}
 
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
    /**
     * collapsedY and achorPointY are calculated every time looking for
     * flexibility, in case that dependency's height, child's height or {@link BottomSheetBehaviorGoogleMapsLike#getPeekHeight()}'s
     * value changes throught the time, I mean, you can have a {@link android.widget.ImageView}
     * using images with different sizes and you don't want to resize them or so
     */
    if (mBottomSheetBehaviorRef == null || mBottomSheetBehaviorRef.get() == null)
        getBottomSheetBehavior(parent);
    /**
     * mCollapsedY: Y position in where backdrop get hidden behind dependency.
     * {@link BottomSheetBehaviorGoogleMapsLike#getPeekHeight()} and collapsedY are the same point on screen.
     */
    int collapsedY = dependency.getHeight() - mBottomSheetBehaviorRef.get().getPeekHeight();
    /**
     * achorPointY: with top being Y=0, achorPointY defines the point in Y where could
     * happen 2 things:
     * The backdrop should be moved behind dependency view (when {@link #mCurrentChildY} got
     * positive values) or the dependency view overlaps the backdrop (when
     * {@link #mCurrentChildY} got negative values)
     */
    int achorPointY = child.getHeight();
    /**
     * lastCurrentChildY: Just to know if we need to return true or false at the end of this
     * method.
     */
    int lastCurrentChildY = mCurrentChildY;

    if((mCurrentChildY = (int) ((dependency.getY()-achorPointY) * collapsedY / (collapsedY-achorPointY))) <= 0)
        child.setY(mCurrentChildY = 0);
    else
        child.setY(mCurrentChildY);
    return (lastCurrentChildY == mCurrentChildY);
}
 
源代码12 项目: materialistic   文件: NavFloatingActionButton.java
@Synthetic
void startDrag(float startX, float startY) {
    if (mVibrationEnabled) {
        mVibrator.vibrate(VIBRATE_DURATION_MS * 2);
    }
    Toast.makeText(getContext(), R.string.hint_drag, Toast.LENGTH_SHORT).show();
    //noinspection Convert2Lambda
    super.setOnTouchListener(new OnTouchListener() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_MOVE:
                    mMoved = true;
                    view.setX(motionEvent.getRawX() - startX); // TODO compensate shift
                    view.setY(motionEvent.getRawY() - startY);
                    break;
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    bindNavigationPad();
                    if (mMoved) {
                        persistPosition();
                    }
                    break;
                default:
                    return false;
            }
            return true;
        }
    });
}
 
源代码13 项目: xDrip   文件: XDripDreamService.java
/**
 * Every TimeAnimator frame, nudge each bouncing view along.
 */
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) {
    final float dt = dt_ms / 1000f; // seconds
    for (int i = 0; i < getChildCount(); i++) {
        final View view = getChildAt(i);
        final PointF v = (PointF) view.getTag();

        // step view for velocity * time
        view.setX(view.getX() + v.x * dt);
        view.setY(view.getY() + v.y * dt);

        // handle reflections
        final float l = view.getX();
        final float t = view.getY();
        final float r = l + view.getWidth();
        final float b = t + view.getHeight();
        boolean flipX = false, flipY = false;
        if (r > mWidth) {
            view.setX(view.getX() - 2 * (r - mWidth));
            flipX = true;
        } else if (l < 0) {
            view.setX(-l);
            flipX = true;
        }
        if (b > mHeight) {
            view.setY(view.getY() - 2 * (b - mHeight));
            flipY = true;
        } else if (t < 0) {
            view.setY(-t);
            flipY = true;
        }
        if (flipX) v.x *= -1;
        if (flipY) v.y *= -1;
    }
}
 
源代码14 项目: nono-android   文件: TransitionCompat.java
/**
 * 开始执行动画的方法
 * @param activity:当前的activity对象
 * @param layoutResId:当前activity的布局文件id,如R.layout.xx
 * @param targetView:要执行动画的控件
 */
private static void startSharedElementAnimation(final Activity activity, int layoutResId) {
	final View orginalView = getSharedElementOrginalView(activity, layoutResId);
	if (orginalView == null) {
		return;
	}
	/**
	 * 根据两个activity是否是全屏来计算开始的坐标和偏移量
	 * 从全屏切换到不全屏就会卡顿,系统为了消除卡顿,可能会做个动画。所以不推荐两个不同模式的Activity相互切换
	 */
	final int finalOffsetY;
	boolean isFinalFullScreen = ActivityOptionsCompatICS.isFullScreen(activity);
	if (mIsStartFullScreen == true && isFinalFullScreen == false) {
		finalOffsetY = -ActivityOptionsCompatICS.getStatusBarHeight(activity);
	}
	else {
		finalOffsetY = 0;
	}
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(mWidth, mHeight);
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(orginalView, orginalParams);
	orginalView.setX(mStartX);
	orginalView.setY(mStartY);
	// 只有通过activity的findviewbyid获得的对象才能用post方法得到bounds,用mInflater不行
	final View targetView = activity.findViewById(mSharedElementId);
	
	/**
	 * 已经获得原始的view并且知道了目标的view区域,开始执行动画
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration(mAnimTime);
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	orginalView.post(new Runnable() {
		
		@Override
		public void run() {
			// 如果目标view现在不在屏幕上那么就不执行动画(必须在显示完成后才能判断是否在屏幕上)
			if (!ActivityOptionsCompatICS.isInScreen(activity, targetView)) {
				targetView.setVisibility(View.VISIBLE);
				((ViewGroup)orginalView.getParent()).removeView(orginalView);
			}else {
				targetView.setVisibility(View.INVISIBLE);
				anim.startViewTweensAnim(orginalView, targetView, 0, finalOffsetY);
			}
		}
	});
}
 
源代码15 项目: Mover   文件: ViewHelper.java
static void setY(View view, float y) {
    view.setY(y);
}
 
源代码16 项目: CircularReveal   文件: DynamicAnimation.java
@Override
public void setValue(View view, float value) {
  view.setY(value);
}
 
源代码17 项目: AndroidStudyDemo   文件: TransitionCompat.java
/**
 * 开始执行动画的方法
 * @param activity:当前的activity对象
 * @param layoutResId:当前activity的布局文件id,如R.layout.xx
 * @param targetView:要执行动画的控件
 */
private static void startSharedElementAnimation(final Activity activity, int layoutResId) {
	final View orginalView = getSharedElementOrginalView(activity, layoutResId);
	if (orginalView == null) {
		return;
	}
	/**
	 * 根据两个activity是否是全屏来计算开始的坐标和偏移量
	 * 从全屏切换到不全屏就会卡顿,系统为了消除卡顿,可能会做个动画。所以不推荐两个不同模式的Activity相互切换
	 */
	final int finalOffsetY;
	boolean isFinalFullScreen = ActivityOptionsCompatICS.isFullScreen(activity);
	if (mIsStartFullScreen == true && isFinalFullScreen == false) {
		finalOffsetY = -ActivityOptionsCompatICS.getStatusBarHeight(activity);
	}
	else {
		finalOffsetY = 0;
	}
	/**
	 * 开始设定view开始时的大小和坐标位置
	 */
	LayoutParams orginalParams = new LayoutParams(mWidth, mHeight);
	ViewGroup rootView = (ViewGroup)(activity.getWindow().getDecorView());
	rootView.addView(orginalView, orginalParams);
	orginalView.setX(mStartX);
	orginalView.setY(mStartY);
	// 只有通过activity的findviewbyid获得的对象才能用post方法得到bounds,用mInflater不行
	final View targetView = activity.findViewById(mSharedElementId);
	
	/**
	 * 已经获得原始的view并且知道了目标的view区域,开始执行动画
	 * 这里可以设置动画的持续时间,开始延迟,添加监听器
	 */
	final ViewAnim anim = new ViewAnim();
	anim.setDuration(mAnimTime);
	anim.setStartDelay(mStartDelay);
	anim.addListener(mViewAnimListener);
	anim.setTimeInterpolator(mInterpolator);
	orginalView.post(new Runnable() {
		
		@Override
		public void run() {
			// 如果目标view现在不在屏幕上那么就不执行动画(必须在显示完成后才能判断是否在屏幕上)
			if (!ActivityOptionsCompatICS.isInScreen(activity, targetView)) {
				targetView.setVisibility(View.VISIBLE);
				((ViewGroup)orginalView.getParent()).removeView(orginalView);
			}else {
				targetView.setVisibility(View.INVISIBLE);
				anim.startViewTweensAnim(orginalView, targetView, 0, finalOffsetY);
			}
		}
	});
}
 
源代码18 项目: FABRevealMenu-master   文件: ViewHelper.java
/**
 * Aligns the sheet's position with the FAB.
 */
public void alignMenuWithFab(View mFab, View mRevealView, Direction mDirection) {
    ViewGroup.MarginLayoutParams sheetLayoutParams = (ViewGroup.MarginLayoutParams)
            mRevealView.getLayoutParams();
    ViewGroup.MarginLayoutParams fabLayoutParams = (ViewGroup.MarginLayoutParams)
            mFab.getLayoutParams();

    //adjust sheet margin
    sheetLayoutParams.setMargins(fabLayoutParams.leftMargin, fabLayoutParams.topMargin, fabLayoutParams.rightMargin, fabLayoutParams.bottomMargin);

    // Get FAB's coordinates
    int[] fabCoords = new int[2];
    mFab.getLocationOnScreen(fabCoords);


    // Get sheet's coordinates
    int[] sheetCoords = new int[2];
    mRevealView.getLocationOnScreen(sheetCoords);

    int leftDiff = Math.max(sheetCoords[0] - fabCoords[0], fabLayoutParams.leftMargin);
    int rightDiff = Math.min((sheetCoords[0] + mRevealView.getWidth()) - (fabCoords[0] + mFab.getWidth()), -fabLayoutParams.rightMargin);
    int topDiff = Math.max(sheetCoords[1] - fabCoords[1], fabLayoutParams.topMargin);
    int bottomDiff = Math.min((sheetCoords[1] + mRevealView.getHeight()) - (fabCoords[1] + mFab.getHeight()), -fabLayoutParams.bottomMargin);

    float sheetX = mRevealView.getX();
    float sheetY = mRevealView.getY();

    if (mDirection == Direction.LEFT || mDirection == Direction.UP) {
        // Align the right side of the sheet with the right side of the FAB
        mRevealView.setX(sheetX - rightDiff - sheetLayoutParams.rightMargin);
        // Align the bottom of the sheet with the bottom of the FAB
        mRevealView.setY(sheetY - bottomDiff - sheetLayoutParams.bottomMargin);
    } else if (mDirection == Direction.RIGHT) {
        // align the left side of the sheet with the left side of the FAB
        mRevealView.setX(sheetX - leftDiff + sheetLayoutParams.leftMargin);
        // Align the bottom of the sheet with the bottom of the FAB
        mRevealView.setY(sheetY - bottomDiff - sheetLayoutParams.bottomMargin);
    } else if (mDirection == Direction.DOWN) {
        // align the top of the sheet with the top of the FAB
        mRevealView.setY(sheetY - topDiff + sheetLayoutParams.topMargin);
        // Align the right side of the sheet with the right side of the FAB
        mRevealView.setX(sheetX - rightDiff - sheetLayoutParams.rightMargin);

    }
}
 
源代码19 项目: MiBandDecompiled   文件: a.java
static void l(View view, float f1)
{
    view.setY(f1);
}
 
源代码20 项目: RxAnimations   文件: RxAnimations.java
public static void set(final View view, final float x, final float y, final float alpha) {
    view.setAlpha(alpha);
    view.setX(x);
    view.setY(y);
}
 
 方法所在类
 同类方法