本文整理汇总了Java中android.view.View.layout方法的典型用法代码示例。如果您正苦于以下问题:Java View.layout方法的具体用法?Java View.layout怎么用?Java View.layout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.layout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);//对子对象进行布局。
if (lp.dropped) {
lp.dropped = false;
final int[] cellXY = mTmpCellXY;
getLocationOnScreen(cellXY);
mWallpaperManager.sendWallpaperCommand(getWindowToken(),
WallpaperManager.COMMAND_DROP,
cellXY[0] + childLeft + lp.width / 2,
cellXY[1] + childTop + lp.height / 2, 0, null);
}
}
}
}
示例2: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
public void onLayout(boolean changed, int l, int t, int r, int b) {
boolean rtl = mHelper.useRtl();
int viewWidth = getMeasuredWidth();
// Initialize horizontal layout cursor. The cursor value increases as layout proceeds, but
// actual layout locations in RTL mode are (viewWidth - cursorX).
int cursorX = getFirstFieldX();
for (int i = 0; i < mFieldViews.size(); i++) {
View view = (View) mFieldViews.get(i);
// Use the width and height of the field's view to compute its placement
int fieldWidth = view.getMeasuredWidth();
int fieldHeight = view.getMeasuredHeight();
int left = rtl ? viewWidth - (cursorX + fieldWidth) : cursorX;
view.layout(left, mBlockTopPadding, left + fieldWidth,
mBlockTopPadding + fieldHeight);
// Move x position left or right, depending on RTL mode.
cursorX += fieldWidth + mHorizontalFieldSpacing;
}
layoutChild();
}
示例3: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
mWidth = getMeasuredWidth();
mHeight = getMeasuredHeight();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CenterLayout.LayoutParams lp = (CenterLayout.LayoutParams) child.getLayoutParams();
int childLeft = mPaddingLeft + lp.x;
if (lp.width > 0)
childLeft += (int) ((mWidth - lp.width) / 2.0);
else
childLeft += (int) ((mWidth - child.getMeasuredWidth()) / 2.0);
int childTop = mPaddingTop + lp.y;
if (lp.height > 0)
childTop += (int) ((mHeight - lp.height) / 2.0);
else
childTop += (int) ((mHeight - child.getMeasuredHeight()) / 2.0);
child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight());
}
}
}
示例4: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
final int width = right - left;
final int height = bottom - top;
// Sub-rectangle specified by percentage values.
final int subWidth = width * widthPercent / 100;
final int subHeight = height * heightPercent / 100;
final int subLeft = left + width * xPercent / 100;
final int subTop = top + height * yPercent / 100;
for (int i = 0; i < getChildCount(); ++i) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
// Center child both vertically and horizontally.
final int childLeft = subLeft + (subWidth - childWidth) / 2;
final int childTop = subTop + (subHeight - childHeight) / 2;
child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
}
}
}
示例5: updateViewSize
import android.view.View; //导入方法依赖的package包/类
private void updateViewSize(Message msg) {
// 重新设置View的宽高
if (msg.obj != null) {
rfView.headerImage.getLayoutParams().height += msg.arg1;
View view = ((View) msg.obj);
view.layout(view.getLeft(), 0, view.getRight(), view.getBottom());
} else {
// 实现类似弹簧的阻力效果,拉的越长就越难拉的动
rfView.headerImageScaleHeight = rfView.headerImage.getLayoutParams().height
- rfView.headerImageHeight;
if (rfView.headerImageScaleHeight < (rfView.headerImageMaxHeight - rfView.headerImageHeight) / 3) {
rfView.headerImage.getLayoutParams().height -= msg.arg1;
} else if (rfView.headerImageScaleHeight > (rfView.headerImageMaxHeight - rfView.headerImageHeight) / 3 * 2) {
rfView.headerImage.getLayoutParams().height -= msg.arg1 / 3 * 2;
} else {
rfView.headerImage.getLayoutParams().height -= msg.arg1 / 3 * 1.5;
}
}
rfView.headerImage.requestLayout();
}
示例6: layoutChild
import android.view.View; //导入方法依赖的package包/类
private void layoutChild(View child) {
int childWidth = child.getMeasuredWidth();
int childHeight = child.getMeasuredHeight();
childRect.top = childCenter.y - childHeight / 2;
childRect.left = childCenter.x - childWidth / 2;
childRect.right = childRect.left + childWidth;
childRect.bottom = childRect.top + childHeight;
child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
}
示例7: layoutChildWithAnchor
import android.view.View; //导入方法依赖的package包/类
private void layoutChildWithAnchor(View child, View anchor, int layoutDirection) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
Rect anchorRect = this.mTempRect1;
Rect childRect = this.mTempRect2;
getDescendantRect(anchor, anchorRect);
getDesiredAnchoredChildRect(child, layoutDirection, anchorRect, childRect);
child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
}
示例8: getDescription
import android.view.View; //导入方法依赖的package包/类
@Override
public Bitmap getDescription( ArtworkFactory factory ) {
View view;
// Inflate the layout in case it has not been inflated yet for this Cover class
if (sDescriptionViewMovie==null) {
inflateDescriptionLayoutMovie(factory);
}
view = sDescriptionViewMovie;
if (checkScraperInfo(factory)) {
sMovieTitle.setText(mMovieInfo.getTitle());
if ((mMovieInfo.getDirectors()!=null) && mMovieInfo.getDirectors().length()>0) {
sMovieDirector.setText(mMovieInfo.getDirectors());
}
else { //fall-back on year if there is no director info
sMovieDirector.setText(Integer.toString(mMovieInfo.getYear()));
}
}
else {
// Scraper info not available or not valid => fall-back on filename (this is not a common expected use-case...)
sMovieTitle.setText(factory.removeFilenameExtension((new File(mFilepath)).getName()));
sMovieDirector.setText("-");
}
if (mDurationMs!=0) {
sMovieDuration.setText(factory.formatTime(mDurationMs));
} else {
sMovieDuration.setText("");
}
// Update the layout setup to take care of the updated text views
view.measure(View.MeasureSpec.makeMeasureSpec(DESCRIPTION_TEXTURE_WIDTH, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(DESCRIPTION_TEXTURE_HEIGHT, View.MeasureSpec.AT_MOST));
view.layout(0, 0, DESCRIPTION_TEXTURE_WIDTH, DESCRIPTION_TEXTURE_HEIGHT);
return factory.createViewBitmap(view, DESCRIPTION_TEXTURE_WIDTH, DESCRIPTION_TEXTURE_HEIGHT);
}
示例9: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != View.GONE) {
child.layout(0, 0, r - l, b - t);
}
}
}
示例10: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
int left = l + getPaddingLeft();
int top = t + getPaddingTop();
// keeps track of maximum row height
int rowHeight = 0;
for(int i = 0; i < count; i++) {
View child = getChildAt(i);
int childWidth = child.getMeasuredWidth();
int childHeight = child.getMeasuredHeight();
// if child fits in this row put it there
if(left + childWidth < r - getPaddingRight()) {
child.layout(left, top, left + childWidth, top + childHeight);
left += childWidth;
} else {
// otherwise put it on next row
left = l + getPaddingLeft();
top += rowHeight;
rowHeight = 0;
}
// update maximum row height
if(childHeight > rowHeight) rowHeight = childHeight;
}
}
示例11: animateDisappearance
import android.view.View; //导入方法依赖的package包/类
public boolean animateDisappearance(@NonNull ViewHolder viewHolder, @NonNull ItemHolderInfo preLayoutInfo, @Nullable ItemHolderInfo postLayoutInfo) {
int oldLeft = preLayoutInfo.left;
int oldTop = preLayoutInfo.top;
View disappearingItemView = viewHolder.itemView;
int newLeft = postLayoutInfo == null ? disappearingItemView.getLeft() : postLayoutInfo.left;
int newTop = postLayoutInfo == null ? disappearingItemView.getTop() : postLayoutInfo.top;
if (viewHolder.isRemoved() || (oldLeft == newLeft && oldTop == newTop)) {
return animateRemove(viewHolder);
}
disappearingItemView.layout(newLeft, newTop, disappearingItemView.getWidth() + newLeft, disappearingItemView.getHeight() + newTop);
return animateMove(viewHolder, oldLeft, oldTop, newLeft, newTop);
}
示例12: onLayout
import android.view.View; //导入方法依赖的package包/类
/**
* 摆放子 View
*
* @param changed 当前控件的尺寸大小, 位置 是否发生了变化
* @param l 左边
* @param t 顶部
* @param r 右边
* @param b 底部
*/
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
View leftMenu = getChildAt(0);
/*摆放 侧面板位置*/
leftMenu.layout(-leftMenu.getMeasuredWidth(), 0, 0, b);
/*摆放主面板*/
getChildAt(1).layout(l, t, r, b);
}
示例13: onLayout
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
if (child instanceof LauncherAppWidgetHostView) {
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;
// Scale and center the widget to fit within its cells.
DeviceProfile profile = mLauncher.getDeviceProfile();
float scaleX = profile.appWidgetScale.x;
float scaleY = profile.appWidgetScale.y;
lahv.setScaleToFit(Math.min(scaleX, scaleY));
lahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
-(lp.height - (lp.height * scaleY)) / 2.0f);
}
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
if (lp.dropped) {
lp.dropped = false;
final int[] cellXY = mTmpCellXY;
getLocationOnScreen(cellXY);
mWallpaperManager.sendWallpaperCommand(getWindowToken(),
WallpaperManager.COMMAND_DROP,
cellXY[0] + childLeft + lp.width / 2,
cellXY[1] + childTop + lp.height / 2, 0, null);
}
}
}
}
示例14: createAndPutChipForUser
import android.view.View; //导入方法依赖的package包/类
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
String name = UserObject.getUserName(user);
if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
name = PhoneFormat.getInstance().format("+" + user.phone);
}
text.setText(name + ", ");
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache();
final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());
SpannableStringBuilder ssb = new SpannableStringBuilder("");
ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
allSpans.add(span);
selectedContacts.put(user.id, span);
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
return span;
}
示例15: processLayoutRequest
import android.view.View; //导入方法依赖的package包/类
private void processLayoutRequest() {
mIsLayoutRequested = false;
for (int i = 0, childCount = getChildCount(); i != childCount; ++i) {
View child = getChildAt(i);
if (!child.isLayoutRequested()) {
continue;
}
child.measure(
MeasureSpec.makeMeasureSpec(child.getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(child.getHeight(), MeasureSpec.EXACTLY));
child.layout(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
}
}