Java Code Examples for android.view.ViewGroup#getHeight()
The following examples show how to use
android.view.ViewGroup#getHeight() .
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: DraggableView.java From AndroidBottomSheet with Apache License 2.0 | 6 votes |
/** * Returns, whether a touch event at a specific position targets a view, which can be scrolled * up. * * @param x * The horizontal position of the touch event in pixels as a {@link Float} value * @param y * The vertical position of the touch event in pixels as a {@link Float} value * @param viewGroup * The view group, which should be used to search for scrollable child views, as an * instance of the class {@link ViewGroup}. The view group may not be null * @return True, if the touch event targets a view, which can be scrolled up, false otherwise */ private boolean isScrollUpEvent(final float x, final float y, @NonNull final ViewGroup viewGroup) { int location[] = new int[2]; viewGroup.getLocationOnScreen(location); if (x >= location[0] && x <= location[0] + viewGroup.getWidth() && y >= location[1] && y <= location[1] + viewGroup.getHeight()) { for (int i = 0; i < viewGroup.getChildCount(); i++) { View view = viewGroup.getChildAt(i); if (view.canScrollVertically(-1)) { return true; } else if (view instanceof ViewGroup) { return isScrollUpEvent(x, y, (ViewGroup) view); } } } return false; }
Example 2
Source File: ControllerPadFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 6 votes |
private void adjustAspectRatio() { ViewGroup rootLayout = mContentView; final int mainWidth = rootLayout.getWidth(); if (mainWidth > 0) { final int mainHeight = rootLayout.getHeight() - mTopSpacerView.getLayoutParams().height - mBottomSpacerView.getLayoutParams().height; if (mainHeight > 0) { // Add black bars if aspect ratio is below min final float aspectRatio = mainWidth / (float) mainHeight; if (aspectRatio < kMinAspectRatio) { final int spacerHeight = Math.round(mainHeight - mainWidth / kMinAspectRatio); ViewGroup.LayoutParams topLayoutParams = mTopSpacerView.getLayoutParams(); topLayoutParams.height = spacerHeight / 2; mTopSpacerView.setLayoutParams(topLayoutParams); ViewGroup.LayoutParams bottomLayoutParams = mBottomSpacerView.getLayoutParams(); bottomLayoutParams.height = spacerHeight / 2; mBottomSpacerView.setLayoutParams(bottomLayoutParams); } } } }
Example 3
Source File: RelativeGuide.java From NewbieGuide with Apache License 2.0 | 6 votes |
private MarginInfo getMarginInfo(@LimitGravity int gravity, ViewGroup viewGroup, View view) { MarginInfo marginInfo = new MarginInfo(); RectF rectF = highLight.getRectF(viewGroup); switch (gravity) { case Gravity.LEFT: marginInfo.gravity = Gravity.RIGHT; marginInfo.rightMargin = (int) (viewGroup.getWidth() - rectF.left + padding); marginInfo.topMargin = (int) rectF.top; break; case Gravity.TOP: marginInfo.gravity = Gravity.BOTTOM; marginInfo.bottomMargin = (int) (viewGroup.getHeight() - rectF.top + padding); marginInfo.leftMargin = (int) rectF.left; break; case Gravity.RIGHT: marginInfo.leftMargin = (int) (rectF.right + padding); marginInfo.topMargin = (int) rectF.top; break; case Gravity.BOTTOM: marginInfo.topMargin = (int) (rectF.bottom + padding); marginInfo.leftMargin = (int) rectF.left; break; } return marginInfo; }
Example 4
Source File: LinearSort.java From spruce-android with MIT License | 6 votes |
@Override public PointF getDistancePoint(ViewGroup parent, List<View> children) { PointF point = super.getDistancePoint(parent, children); switch (direction) { case TOP_TO_BOTTOM: return new PointF(parent.getWidth() / 2.0F, 0F); case BOTTOM_TO_TOP: return new PointF(parent.getWidth() / 2.0F, parent.getHeight()); case LEFT_TO_RIGHT: return new PointF(0F, parent.getHeight() / 2.0F); case RIGHT_TO_LEFT: return new PointF(parent.getWidth(), parent.getHeight() / 2.0F); default: throw new AssertionError("Must be a valid Direction argument type"); } }
Example 5
Source File: ZoomOutDownAnimator.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void prepare(View target) { ViewGroup parent = (ViewGroup)target.getParent(); int distance = parent.getHeight() - target.getTop(); getAnimatorAgent().playTogether( ObjectAnimator.ofFloat(target, "alpha",1, 1,0), ObjectAnimator.ofFloat(target,"scaleX",1,0.475f,0.1f), ObjectAnimator.ofFloat(target,"scaleY",1,0.475f,0.1f), ObjectAnimator.ofFloat(target,"translationY",0,-60,distance) ); }
Example 6
Source File: DefaultTransformer.java From FantasySlide with Apache License 2.0 | 5 votes |
@Override public void apply(ViewGroup sideBar, View itemView, float touchY, float slideOffset, boolean isLeft) { float translationX; int centerY = itemView.getTop() + itemView.getHeight() / 2; float distance = Math.abs(touchY - centerY); float scale = distance / sideBar.getHeight() * 3; // 距离中心点距离与 sideBar 的 1/3 对比 if (isLeft) { translationX = Math.max(0, maxTranslationX - scale * maxTranslationX); } else { translationX = Math.min(0, maxTranslationX - scale * maxTranslationX); } itemView.setTranslationX(translationX * slideOffset); }
Example 7
Source File: ZoomInUpAnimator.java From KUtils with Apache License 2.0 | 5 votes |
@Override public void prepare(View target) { ViewGroup parent = (ViewGroup) target.getParent(); int distance = parent.getHeight() - target.getTop(); getAnimatorAgent().playTogether( ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1), ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.475f, 1), ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.475f, 1), ObjectAnimator.ofFloat(target, "translationY", distance, -60, 0) ); }
Example 8
Source File: SlideInUpAnimator.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void prepare(View target) { ViewGroup parent = (ViewGroup)target.getParent(); int distance = parent.getHeight() - target.getTop(); getAnimatorAgent().playTogether( ObjectAnimator.ofFloat(target, "alpha", 0, 1), ObjectAnimator.ofFloat(target,"translationY",distance,0) ); }
Example 9
Source File: ZoomOutDownAnimator.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void prepare(View target) { ViewGroup parent = (ViewGroup)target.getParent(); int distance = parent.getHeight() - target.getTop(); getAnimatorAgent().playTogether( ObjectAnimator.ofFloat(target, "alpha",1, 1,0), ObjectAnimator.ofFloat(target,"scaleX",1,0.475f,0.1f), ObjectAnimator.ofFloat(target,"scaleY",1,0.475f,0.1f), ObjectAnimator.ofFloat(target,"translationY",0,-60,distance) ); }
Example 10
Source File: MenuDialogAdapter.java From MarketAndroidApp with Apache License 2.0 | 5 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(mContext).inflate(R.layout.main_menu_item, null); } //绑定item内的TextView和RadioButton TextView nameText = MenuDialogAdapterViewHolder.get(convertView, R.id.menu_item_textview); RadioButton clickButton = MenuDialogAdapterViewHolder.get(convertView, R.id.radioButton); clickButton.setChecked(selectedPos == position);//改变点击选中状态 //修改item高度,使其达到甲方要求的每页10个item显示要求 ViewGroup.LayoutParams lp = nameText.getLayoutParams(); lp.height = parent.getHeight() / 10; //获取选中的item的标题 CommodityTypeModel menuData = menuDatas.get(position); String str = menuData.getName(); nameText.setText(str);//设置标题 convertView.setSelected(selectedPos == position);//设置选中时的view nameText.setSelected(selectedPos == position);//判断菜单的点击状态 //选中后的标题字体及RadioButton颜色 nameText.setTextColor(selectedPos == position ? 0xFF387ef5 : 0xFF222222); clickButton.setTextColor(selectedPos == position ? 0xFF787878 : 0xFF387ef5); return convertView; }
Example 11
Source File: VideoView.java From HPlayer with Apache License 2.0 | 5 votes |
/** * Set the display options * * @param layout <ul> * <li>{@link #VIDEO_LAYOUT_ORIGIN} * <li>{@link #VIDEO_LAYOUT_SCALE} * <li>{@link #VIDEO_LAYOUT_STRETCH} * <li>{@link #VIDEO_LAYOUT_FIT_PARENT} * <li>{@link #VIDEO_LAYOUT_ZOOM} * </ul> * @param aspectRatio video aspect ratio, will audo detect if 0. */ public void setVideoLayout(int layout, float aspectRatio) { LayoutParams lp = getLayoutParams(); Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext); int windowWidth = res.first.intValue(), windowHeight = res.second.intValue(); float windowRatio = windowWidth / (float) windowHeight; float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio; mSurfaceHeight = mVideoHeight; mSurfaceWidth = mVideoWidth; if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) { lp.width = (int) (mSurfaceHeight * videoRatio); lp.height = mSurfaceHeight; } else if (layout == VIDEO_LAYOUT_ZOOM) { lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight); lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio); } else if (layout == VIDEO_LAYOUT_FIT_PARENT) { ViewGroup parent = (ViewGroup) getParent(); float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight()); lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio); lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio); } else { boolean full = layout == VIDEO_LAYOUT_STRETCH; lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight); lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio); } setLayoutParams(lp); getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight); Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio); mVideoLayout = layout; mAspectRatio = aspectRatio; // 初始化 videoWidth = lp.width; videoHeight = lp.height; currentScale = 1f; }
Example 12
Source File: CircularShape.java From hintcase with Apache License 2.0 | 5 votes |
@Override public void setShapeInfo(View targetView, ViewGroup parent, int offset, Context context) { if (targetView != null) { minRadius = (Math.max(targetView.getMeasuredWidth(),targetView.getMeasuredHeight()) / 2) + offset; maxRadius = Math.max(parent.getHeight(), parent.getWidth()); int[] targetViewLocationInWindow = new int[2]; targetView.getLocationInWindow(targetViewLocationInWindow); setCenterX(targetViewLocationInWindow[0] + targetView.getWidth() / 2); setCenterY(targetViewLocationInWindow[1] + targetView.getHeight() / 2); setLeft((int) (getCenterX() - minRadius)); setRight((int) (getCenterX() + minRadius)); setTop((int) (getCenterY() - minRadius)); setBottom((int) (getCenterY() + minRadius)); setWidth(minRadius * 2); setHeight(minRadius * 2); } else { if (parent != null) { minRadius = 0; maxRadius = parent.getHeight(); setCenterX(parent.getMeasuredWidth() / 2); setCenterY(parent.getMeasuredHeight() / 2); setLeft(0); setTop(0); setRight(0); setBottom(0); } } currentRadius = maxRadius; }
Example 13
Source File: SidePropagation.java From Transitions-Everywhere with Apache License 2.0 | 5 votes |
@SuppressLint("RtlHardcoded") private int getMaxDistance(@NonNull ViewGroup sceneRoot) { switch (mSide) { case Gravity.LEFT: case Gravity.RIGHT: case Gravity.START: case Gravity.END: return sceneRoot.getWidth(); default: return sceneRoot.getHeight(); } }
Example 14
Source File: ZoomOutDownAnimator.java From KUtils with Apache License 2.0 | 5 votes |
@Override protected void prepare(View target) { ViewGroup parent = (ViewGroup) target.getParent(); int distance = parent.getHeight() - target.getTop(); getAnimatorAgent().playTogether( ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0), ObjectAnimator.ofFloat(target, "scaleX", 1, 0.475f, 0.1f), ObjectAnimator.ofFloat(target, "scaleY", 1, 0.475f, 0.1f), ObjectAnimator.ofFloat(target, "translationY", 0, -60, distance) ); }
Example 15
Source File: IncrementalMountUtils.java From litho with Apache License 2.0 | 5 votes |
/** * Performs incremental mount on the children views of the given ViewGroup. * * @param scrollingViewParent ViewGroup container of views that will be incrementally mounted. */ public static void performIncrementalMount(ViewGroup scrollingViewParent) { assertMainThread(); final int viewGroupWidth = scrollingViewParent.getWidth(); final int viewGroupHeight = scrollingViewParent.getHeight(); for (int i = 0; i < scrollingViewParent.getChildCount(); i++) { maybePerformIncrementalMountOnView( viewGroupWidth, viewGroupHeight, scrollingViewParent.getChildAt(i)); } }
Example 16
Source File: MorphTransform.java From android-proguards with Apache License 2.0 | 4 votes |
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { final Animator changeBounds = super.createAnimator(sceneRoot, startValues, endValues); if (changeBounds == null) return null; TimeInterpolator interpolator = getInterpolator(); if (interpolator == null) { interpolator = AnimUtils.getFastOutSlowInInterpolator(sceneRoot.getContext()); } final MorphDrawable background = new MorphDrawable(startColor, startCornerRadius); endValues.view.setBackground(background); final Animator color = ObjectAnimator.ofArgb(background, MorphDrawable.COLOR, endColor); final Animator corners = ObjectAnimator.ofFloat(background, MorphDrawable.CORNER_RADIUS, endCornerRadius); // ease in the dialog's child views (fade in & staggered slide up) if (endValues.view instanceof ViewGroup) { final ViewGroup vg = (ViewGroup) endValues.view; final long duration = getDuration() / 2; float offset = vg.getHeight() / 3; for (int i = 0; i < vg.getChildCount(); i++) { View v = vg.getChildAt(i); v.setTranslationY(offset); v.setAlpha(0f); v.animate() .alpha(1f) .translationY(0f) .setDuration(duration) .setStartDelay(duration) .setInterpolator(interpolator); offset *= 1.8f; } } final AnimatorSet transition = new AnimatorSet(); transition.playTogether(changeBounds, corners, color); transition.setDuration(getDuration()); transition.setInterpolator(interpolator); return transition; }
Example 17
Source File: SidePropagation.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public long getStartDelay(ViewGroup sceneRoot, Transition transition, TransitionValues startValues, TransitionValues endValues) { if (startValues == null && endValues == null) { return 0; } int directionMultiplier = 1; Rect epicenter = transition.getEpicenter(); TransitionValues positionValues; if (endValues == null || getViewVisibility(startValues) == View.VISIBLE) { positionValues = startValues; directionMultiplier = -1; } else { positionValues = endValues; } int viewCenterX = getViewX(positionValues); int viewCenterY = getViewY(positionValues); int[] loc = new int[2]; sceneRoot.getLocationOnScreen(loc); int left = loc[0] + Math.round(sceneRoot.getTranslationX()); int top = loc[1] + Math.round(sceneRoot.getTranslationY()); int right = left + sceneRoot.getWidth(); int bottom = top + sceneRoot.getHeight(); int epicenterX; int epicenterY; if (epicenter != null) { epicenterX = epicenter.centerX(); epicenterY = epicenter.centerY(); } else { epicenterX = (left + right) / 2; epicenterY = (top + bottom) / 2; } float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY, left, top, right, bottom); float maxDistance = getMaxDistance(sceneRoot); float distanceFraction = distance/maxDistance; long duration = transition.getDuration(); if (duration < 0) { duration = 300; } return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction); }
Example 18
Source File: SidePropagation.java From Transitions-Everywhere with Apache License 2.0 | 4 votes |
@Override public long getStartDelay(@NonNull ViewGroup sceneRoot, @NonNull Transition transition, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) { if (startValues == null && endValues == null) { return 0; } int directionMultiplier = 1; Rect epicenter = transition.getEpicenter(); TransitionValues positionValues; if (endValues == null || getViewVisibility(startValues) == View.VISIBLE) { positionValues = startValues; directionMultiplier = -1; } else { positionValues = endValues; } int viewCenterX = getViewX(positionValues); int viewCenterY = getViewY(positionValues); int[] loc = new int[2]; sceneRoot.getLocationOnScreen(loc); int left = loc[0] + Math.round(sceneRoot.getTranslationX()); int top = loc[1] + Math.round(sceneRoot.getTranslationY()); int right = left + sceneRoot.getWidth(); int bottom = top + sceneRoot.getHeight(); int epicenterX; int epicenterY; if (epicenter != null) { epicenterX = epicenter.centerX(); epicenterY = epicenter.centerY(); } else { epicenterX = (left + right) / 2; epicenterY = (top + bottom) / 2; } float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY, left, top, right, bottom); float maxDistance = getMaxDistance(sceneRoot); float distanceFraction = distance/maxDistance; long duration = transition.getDuration(); if (duration < 0) { duration = 300; } return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction); }
Example 19
Source File: NeopixelFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 4 votes |
private void createBoardUI(@NonNull Board board) { final ViewGroup canvasView = mBoardContentView; canvasView.removeAllViews(); final int kLedSize = (int) MetricsUtils.convertDpToPixel(getContext(), kLedPixelSize); final int canvasViewWidth = canvasView.getWidth(); final int canvasViewHeight = canvasView.getHeight(); final int boardWidth = board.width * kLedSize; final int boardHeight = board.height * kLedSize; final int marginLeft = (canvasViewWidth - boardWidth) / 2; final int marginTop = (canvasViewHeight - boardHeight) / 2; for (int j = 0, k = 0; j < board.height; j++) { for (int i = 0; i < board.width; i++, k++) { View ledView = LayoutInflater.from(getContext()).inflate(R.layout.layout_neopixel_led, canvasView, false); Button ledButton = ledView.findViewById(R.id.ledButton); ledButton.setOnClickListener(view -> { if (mBoard != null) { int tag = (Integer) view.getTag(); byte x = (byte) (tag % mBoard.width); byte y = (byte) (tag / mBoard.width); Log.d(TAG, "led (" + x + "," + y + ")"); setViewBackgroundColor(view, mCurrentColor); setPixelColor(mCurrentColor, mColorW, x, y, null); mBoardCachedColors.set(y * mBoard.width + x, mCurrentColor); } }); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(kLedSize, kLedSize); layoutParams.leftMargin = i * kLedSize + marginLeft; layoutParams.topMargin = j * kLedSize + marginTop; ledView.setLayoutParams(layoutParams); ledButton.setTag(k); setViewBackgroundColor(ledButton, kDefaultLedColor); canvasView.addView(ledView); } } // Setup initial scroll and scale resetScaleAndPanning(board); }
Example 20
Source File: ScrollingUtil.java From AgentWebX5 with Apache License 2.0 | 4 votes |
public static boolean isViewGroupToBottom(ViewGroup viewGroup) { View subChildView = viewGroup.getChildAt(0); return (subChildView != null && subChildView.getMeasuredHeight() <= viewGroup.getScrollY() + viewGroup.getHeight()); }