Java Code Examples for android.view.ViewGroup#layout()

The following examples show how to use android.view.ViewGroup#layout() . These examples are extracted from open source projects. 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
/**
 * close surface
 *
 * @param smooth
 *            smoothly or not.
 * @param notify
 *            if notify all the listeners.
 */
public void close(boolean smooth, boolean notify) {
    ViewGroup surface = getSurfaceView();
    int dx, dy;
    if (smooth)
        mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(),
                getPaddingTop());
    else {
        Rect rect = computeSurfaceLayoutArea(false);
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if (notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right,
                    rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        } else {
            safeBottomView();
        }
    }
    invalidate();
}
 
Example 2
/**
 * close surface
 *
 * @param smooth smoothly or not.
 * @param notify if notify all the listeners.
 */
public void close(boolean smooth, boolean notify) {
    ViewGroup surface = getSurfaceView();
    int dx, dy;
    if (smooth)
        mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(),
                getPaddingTop());
    else {
        Rect rect = computeSurfaceLayoutArea(false);
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if (notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right,
                    rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        } else {
            safeBottomView();
        }
    }
    invalidate();
}
 
Example 3
Source Project: AutoLoadListView   File: ZSwipeItem.java    License: Apache License 2.0 6 votes vote down vote up
public void close(boolean smooth, boolean notify) {
	ViewGroup surface = getSurfaceView();
	int dx, dy;
	if (smooth)
		mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(),
				getPaddingTop());
	else {
		Rect rect = computeSurfaceLayoutArea(false);
		dx = rect.left - surface.getLeft();
		dy = rect.top - surface.getTop();
		surface.layout(rect.left, rect.top, rect.right, rect.bottom);
		if (notify) {
			dispatchSwipeEvent(rect.left, rect.top, dx, dy);
		} else {
			safeBottomView();
		}
	}
	invalidate();
}
 
Example 4
Source Project: ZListVIew   File: ZSwipeItem.java    License: Apache License 2.0 6 votes vote down vote up
public void close(boolean smooth, boolean notify) {
	ViewGroup surface = getSurfaceView();
	int dx, dy;
	if (smooth)
		mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(),
				getPaddingTop());
	else {
		Rect rect = computeSurfaceLayoutArea(false);
		dx = rect.left - surface.getLeft();
		dy = rect.top - surface.getTop();
		surface.layout(rect.left, rect.top, rect.right, rect.bottom);
		if (notify) {
			dispatchSwipeEvent(rect.left, rect.top, dx, dy);
		} else {
			safeBottomView();
		}
	}
	invalidate();
}
 
Example 5
Source Project: UltimateAndroid   File: SwipeLayout.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * close surface
 * @param smooth smoothly or not.
 * @param notify if notify all the listeners.
 */
public void close(boolean smooth, boolean notify){
    ViewGroup surface = getSurfaceView();
    int dx, dy;
    if(smooth)
        mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
    else {
        Rect rect = computeSurfaceLayoutArea(false);
        dx = rect.left - surface.getLeft();
        dy = rect.top - surface.getTop();
        surface.layout(rect.left, rect.top, rect.right, rect.bottom);
        if(notify) {
            dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
            dispatchSwipeEvent(rect.left, rect.top, dx, dy);
        }else{
            safeBottomView();
        }
    }
    invalidate();
}
 
Example 6
@Override
protected void setUp() throws Exception {
    super.setUp();

    mFocusFinder = FocusFinder.getInstance();

    // inflate the layout
    final Context context = getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    mRoot = (ViewGroup) inflater.inflate(R.layout.focus_2, null);

    // manually measure it, and lay it out
    mRoot.measure(500, 500);
    mRoot.layout(0, 0, 500, 500);

    mLeftButton = (Button) mRoot.findViewById(R.id.leftButton);
    mCenterButton = (Button) mRoot.findViewById(R.id.centerButton);
    mRightButton = (Button) mRoot.findViewById(R.id.rightButton);
}
 
Example 7
Source Project: litho   File: ComponentTestHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Mount a component tree into a component view.
 *
 * @param lithoView The view to mount the component tree into
 * @param componentTree The component tree to mount
 * @param widthSpec The width spec used to measure the resulting view
 * @param heightSpec The height spec used to measure the resulting view
 * @return A LithoView with the component tree mounted in it.
 */
public static LithoView mountComponent(
    LithoView lithoView, ComponentTree componentTree, int widthSpec, int heightSpec) {
  final boolean addParent = lithoView.getParent() == null;
  final ViewGroup parent =
      new ViewGroup(lithoView.getContext()) {
        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {}
      };

  if (addParent) {
    parent.addView(lithoView);
  }

  lithoView.setComponentTree(componentTree);

  try {
    Whitebox.invokeMethod(lithoView, "onAttach");
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  lithoView.measure(widthSpec, heightSpec);

  if (addParent) {
    parent.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight());
  }

  lithoView.layout(0, 0, lithoView.getMeasuredWidth(), lithoView.getMeasuredHeight());

  return lithoView;
}
 
Example 8
Source Project: CommentGallery   File: CommentImageGrid.java    License: Apache License 2.0 5 votes vote down vote up
private void layoutChildrenView() {
    int childrenCount = getChildCount();

    for (int i = 0; i < childrenCount; i++) {
        ViewGroup childImageLayout = (ViewGroup) getChildAt(i);
        SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0);
        if (mOnItemClickListener != null) {
            final int finalI = i;
            childImageLayout.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItemClick(finalI);
                }
            });
        }
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i)))
                .setProgressiveRenderingEnabled(true)
                .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth))
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(childImageView.getController())
                .build();
        childImageView.setController(controller);

        int[] position = findPosition(i);
        int itemHeight = mItemWidth;
        int left = (int) (mItemWidth + mHorizontalSpace) * position[1];
        int top = (int) (itemHeight + mVerticalSpace) * position[0];
        int right = left + mItemWidth;
        int bottom = top + itemHeight;

        childImageLayout.layout(left, top, right, bottom);
    }
}
 
Example 9
Source Project: FoldableLayout   File: FoldableLayout.java    License: Apache License 2.0 5 votes vote down vote up
private Bitmap computeBitmap(ViewGroup viewGroup) {
    Bitmap bitmap;
    Rect rect = new Rect();
    viewGroup.getWindowVisibleDisplayFrame(rect);
    viewGroup.destroyDrawingCache();
    viewGroup.setDrawingCacheEnabled(true);
    viewGroup.buildDrawingCache(true);
    bitmap = viewGroup.getDrawingCache(true);
    /**
     * After rotation, the DecorView has no height and no width. Therefore
     * .getDrawingCache() return null. That's why we  have to force measure and layout.
     */
    if (bitmap == null) {
        viewGroup.measure(
                MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(mCoverHeight * 2, MeasureSpec.EXACTLY)
        );
        viewGroup.layout(0, 0, viewGroup.getMeasuredWidth(),
                viewGroup.getMeasuredHeight());
        viewGroup.destroyDrawingCache();
        viewGroup.setDrawingCacheEnabled(true);
        viewGroup.buildDrawingCache(true);
        bitmap = viewGroup.getDrawingCache(true);
    }
    if (bitmap == null) {
        return Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
    } else {
        return bitmap.copy(Bitmap.Config.ARGB_8888, false);
    }
}