下面列出了android.view.ViewGroup#layout ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
/**
* 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();
}
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();
}
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();
}
/**
* 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();
}
@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);
}
/**
* 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;
}
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);
}
}
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);
}
}