List of usage examples for android.view View getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:Main.java
public static Point getPointOnView(View root, View target) { final int[] l0 = new int[2]; root.getLocationOnScreen(l0);/*from www . ja va2 s . c o m*/ final int[] l1 = new int[2]; target.getLocationOnScreen(l1); l1[0] = l1[0] - l0[0] + target.getWidth() / 2; l1[1] = l1[1] - l0[1] + target.getHeight() / 2; return new Point(l1[0], l1[1]); }
From source file:Main.java
public static void dispatchTouch(final View view, final long duration) { final long downTime = SystemClock.uptimeMillis(); final long eventTime = SystemClock.uptimeMillis(); final float x = view.getWidth() / 3;//0.0f; final float y = view.getHeight() / 3;//0.0f; // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState() final int metaState = 0; MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, metaState); // Dispatch touch event to view view.dispatchTouchEvent(motionEvent); new Handler().postDelayed(new Runnable() { @Override/*w ww. j a v a2 s. c o m*/ public void run() { MotionEvent motionEvent = MotionEvent.obtain(downTime + duration, eventTime + duration, MotionEvent.ACTION_UP, x, y, metaState); view.dispatchTouchEvent(motionEvent); } }, duration); }
From source file:Main.java
public static boolean inRangeOfView(View view, MotionEvent ev) { int[] location = new int[2]; view.getLocationOnScreen(location);// www.j a v a 2 s .c o m int x = location[0]; int y = location[1]; if (ev.getX() < x || ev.getX() > (x + view.getWidth()) || ev.getY() < y || ev.getY() > (y + view.getHeight())) { return false; } return true; }
From source file:Main.java
public static boolean isInRangeOfView(View view, MotionEvent ev) { int[] location = new int[2]; view.getLocationOnScreen(location);// ww w . j a va 2 s . c o m int x = location[0]; int y = location[1]; if (ev.getRawX() < x || ev.getRawX() > (x + view.getWidth()) || ev.getRawY() < y || ev.getRawY() > (y + view.getHeight())) { return false; } return true; }
From source file:Main.java
public static boolean isTouchInView(MotionEvent ev, View v) { int[] vLoc = new int[2]; v.getLocationOnScreen(vLoc);/*from w ww . j av a 2s .c om*/ float motionX = ev.getRawX(); float motionY = ev.getRawY(); return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth()) && motionY >= vLoc[1] && motionY <= (vLoc[1] + v.getHeight()); }
From source file:Main.java
public static int getCentWidthByView(View view) { final int mMeasuredWidth = View.MeasureSpec.getSize(view.getMeasuredWidth()); Log.i("width", "mywidth--" + mMeasuredWidth); final int mWidth = View.MeasureSpec.getSize(view.getWidth()); Log.i("width", "mywidth--" + mWidth); return (int) ((float) mWidth / 2 + 0.5f); }
From source file:com.andryr.guitartuner.Utils.java
public static void scrollToPosition(RecyclerView recyclerView, int position) { LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager(); int recyclerWidth = recyclerView.getWidth(); View itemView = lm.findViewByPosition(position); if (itemView != null) { int viewWidth = itemView.getWidth(); lm.scrollToPositionWithOffset(position, -(recyclerWidth - viewWidth) / 2); }// w ww .j a v a 2s .c o m }
From source file:Main.java
public static Animation slideIn(View view, int from) { view.setVisibility(View.VISIBLE); Animation anim;/* www .ja va 2 s . c o m*/ switch (from) { case DIRECTION_LEFT: anim = new TranslateAnimation(-view.getWidth(), 0, 0, 0); break; case DIRECTION_RIGHT: anim = new TranslateAnimation(view.getWidth(), 0, 0, 0); break; case DIRECTION_UP: anim = new TranslateAnimation(0, 0, -view.getHeight(), 0); break; case DIRECTION_DOWN: anim = new TranslateAnimation(0, 0, view.getHeight(), 0); break; default: throw new IllegalArgumentException(Integer.toString(from)); } anim.setDuration(500); view.startAnimation(anim); return anim; }
From source file:Main.java
/** * Get translate animation of PathButton.<br> * The visibility of path button and anchor view must be * {@link View#VISIBLE} or {@link View#INVISIBLE}. * * @param isOpen Is open for button//from w w w. j a v a2 s.c om * @param button Path button * @param anchor Control button * @return Animation */ public static Animation animOfPathButton(boolean isOpen, View button, View anchor) { int[] anchorL = new int[2]; anchor.getLocationOnScreen(anchorL); int[] buttonL = new int[2]; button.getLocationOnScreen(buttonL); int x = anchorL[0] - buttonL[0] + (anchor.getWidth() - button.getWidth()) / 2; int y = anchorL[1] - buttonL[1] + (anchor.getHeight() - button.getHeight()) / 2; TranslateAnimation anim = new TranslateAnimation(Animation.ABSOLUTE, isOpen ? x : 0, Animation.ABSOLUTE, isOpen ? 0 : x, Animation.ABSOLUTE, isOpen ? y : 0, Animation.ABSOLUTE, isOpen ? 0 : y); anim.setDuration(300); anim.setFillAfter(true); return anim; }
From source file:Main.java
public static Bitmap crop(Bitmap srcBmp, View canvasView, int downsampling) { float scale = 1f / downsampling; return Bitmap.createBitmap(srcBmp, (int) Math.floor((canvasView.getX()) * scale), (int) Math.floor((canvasView.getY()) * scale), (int) Math.floor((canvasView.getWidth()) * scale), (int) Math.floor((canvasView.getHeight()) * scale)); }