本文整理汇总了Java中android.view.View.measure方法的典型用法代码示例。如果您正苦于以下问题:Java View.measure方法的具体用法?Java View.measure怎么用?Java View.measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.measure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: measureHeight
import android.view.View; //导入方法依赖的package包/类
private int measureHeight(int measureSpec) {
int mode = MeasureSpec.getMode(measureSpec);
if (mode == MeasureSpec.AT_MOST) {
return MeasureSpec.makeMeasureSpec(measureSpec, mode);
} else if (mode == MeasureSpec.EXACTLY) {
ListAdapter adapter = getAdapter();
if (adapter == null) {
measureSpec = 0;
} else {
int result = 0;
for (int i = 0; i < adapter.getCount(); i++) {
View contentView = adapter.getView(i, null, null);
contentView.measure(0, 0);
result += contentView.getMeasuredHeight();
}
measureSpec = result + getDividerHeight()
* (adapter.getCount() - 1);
}
}
return MeasureSpec.makeMeasureSpec(measureSpec, mode);
}
示例2: measureContentWidth
import android.view.View; //导入方法依赖的package包/类
public int measureContentWidth() {
// The user may have specified some of the target not to be shown but we
// want to measure all of them since after expansion they should fit.
final int oldMaxActivityCount = mMaxActivityCount;
mMaxActivityCount = MAX_ACTIVITY_COUNT_UNLIMITED;
int contentWidth = 0;
View itemView = null;
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
final int count = getCount();
for (int i = 0; i < count; i++) {
itemView = getView(i, itemView, null);
itemView.measure(widthMeasureSpec, heightMeasureSpec);
contentWidth = Math.max(contentWidth, itemView.getMeasuredWidth());
}
mMaxActivityCount = oldMaxActivityCount;
return contentWidth;
}
示例3: setExpandedListViewHeightBasedOnChildren
import android.view.View; //导入方法依赖的package包/类
public static void setExpandedListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) {
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
if (listAdapter == null) {
return;
}
View listItem = listAdapter.getChildView(groupPosition, 0, true, null,
listView);
listItem.measure(0, 0);
int appendHeight = 0;
for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) {
appendHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height += appendHeight;
listView.setLayoutParams(params);
}
示例4: doInBackground
import android.view.View; //导入方法依赖的package包/类
@Nullable
@Override
protected final Bitmap doInBackground(@NonNull final Tab key,
@NonNull final TabItem... params) {
TabItem tabItem = params[0];
PhoneTabViewHolder viewHolder = tabItem.getViewHolder();
View child = viewHolder.child;
viewHolder.child = null;
int width = parent.getWidth();
int height = parent.getHeight();
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
child.draw(canvas);
return bitmap;
}
示例5: onMeasure
import android.view.View; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int cellWidthSpec = MeasureSpec.makeMeasureSpec(mCellWidth,
MeasureSpec.AT_MOST);
int cellHeightSpec = MeasureSpec.makeMeasureSpec(mCellHeight,
MeasureSpec.AT_MOST);
int count = getChildCount();
for (int index=0; index<count; index++) {
final View child = getChildAt(index);
child.measure(cellWidthSpec, cellHeightSpec);
}
// Use the size our parents gave us
setMeasuredDimension(resolveSize(mCellWidth*count, widthMeasureSpec),
resolveSize(mCellHeight*count, heightMeasureSpec));
}
示例6: getMenuOptionPopup
import android.view.View; //导入方法依赖的package包/类
/** A popup to select the type of message to send, "Text", "Image", "Location".*/
public static PopupWindow getMenuOptionPopup(Context context, View.OnClickListener listener){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.chat_sdk_popup_options, null);
PopupWindow optionPopup = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
popupView.findViewById(R.id.chat_sdk_btn_choose_picture).setOnClickListener(listener);
popupView.findViewById(R.id.chat_sdk_btn_take_picture).setOnClickListener(listener);
popupView.findViewById(R.id.chat_sdk_btn_location).setOnClickListener(listener);
if (!BDefines.Options.LocationEnabled || context.getString(R.string.google_maps_api_key).isEmpty()){
popupView.findViewById(R.id.chat_sdk_btn_location).setVisibility(View.GONE);
}
popupView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// TODO fix popup size to wrap view size.
optionPopup.setContentView(popupView);
optionPopup.setBackgroundDrawable(new BitmapDrawable());
optionPopup.setOutsideTouchable(true);
optionPopup.setWidth(popupView.getMeasuredWidth());
optionPopup.setHeight(popupView.getMeasuredHeight());
return optionPopup;
}
示例7: resolveView
import android.view.View; //导入方法依赖的package包/类
/**
* Updates View bounds, possibly re-measuring and re-layouting it if the size changed.
*
* @param reactTag reactTag to lookup a View by
* @param left left coordinate relative to parent
* @param top top coordinate relative to parent
* @param right right coordinate relative to parent
* @param bottom bottom coordinate relative to parent
*/
/* package */ void updateViewBounds(int reactTag, int left, int top, int right, int bottom) {
View view = resolveView(reactTag);
int width = right - left;
int height = bottom - top;
if (view.getWidth() != width || view.getHeight() != height) {
// size changed, we need to measure and layout the View
view.measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
view.layout(left, top, right, bottom);
} else {
// same size, only location changed, there is a faster route.
view.offsetLeftAndRight(left - view.getLeft());
view.offsetTopAndBottom(top - view.getTop());
}
}
示例8: ensurePinnedHeaderLayout
import android.view.View; //导入方法依赖的package包/类
private void ensurePinnedHeaderLayout(View header, boolean forceLayout) {
if (header.isLayoutRequested() || forceLayout) {
int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
try {
header.measure(widthSpec, heightSpec);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
}
}
示例9: getSingleLineHeight
import android.view.View; //导入方法依赖的package包/类
@Override
public int getSingleLineHeight() {
//将所有类型弹幕的布局拿出来,找到高度最大值,作为弹道高度
View view = LayoutInflater.from(context).inflate(R.layout.item_danmu, null);
//指定行高
view.measure(0, 0);
View view2 = LayoutInflater.from(context).inflate(R.layout.item_super_danmu, null);
//指定行高
view2.measure(0, 0);
// return Math.max(view.getMeasuredHeight(),view2.getMeasuredHeight());
return view.getMeasuredHeight();
}
示例10: measureView
import android.view.View; //导入方法依赖的package包/类
private void measureView(View v) {
// See what size the view wants to be
v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
if (!mReflow) {
// Work out a scale that will fit it to this view
float scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
(float)getHeight()/(float)v.getMeasuredHeight());
// Use the fitting values scaled by our current scale factor
v.measure(View.MeasureSpec.EXACTLY | (int)(v.getMeasuredWidth()*scale*mScale),
View.MeasureSpec.EXACTLY | (int)(v.getMeasuredHeight()*scale*mScale));
} else {
v.measure(View.MeasureSpec.EXACTLY | (int)(v.getMeasuredWidth()),
View.MeasureSpec.EXACTLY | (int)(v.getMeasuredHeight()));
}
}
示例11: measureView
import android.view.View; //导入方法依赖的package包/类
private void measureView(View child) {
int childHeightSpec;
ViewGroup.LayoutParams p = child.getLayoutParams();
if (p == null) {
p = new ViewGroup.LayoutParams(-1, -2);
}
int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
int lpHeight = p.height;
if (lpHeight > 0) {
childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, 1073741824);
} else {
childHeightSpec = MeasureSpec.makeMeasureSpec(0, 0);
}
child.measure(childWidthSpec, childHeightSpec);
}
示例12: measureChildWithMargins
import android.view.View; //导入方法依赖的package包/类
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
Rect insets = this.mRecyclerView.getItemDecorInsetsForChild(child);
heightUsed += insets.top + insets.bottom;
int widthSpec = getChildMeasureSpec(getWidth(), getWidthMode(), (((getPaddingLeft() + getPaddingRight()) + lp.leftMargin) + lp.rightMargin) + (widthUsed + (insets.left + insets.right)), lp.width, canScrollHorizontally());
int heightSpec = getChildMeasureSpec(getHeight(), getHeightMode(), (((getPaddingTop() + getPaddingBottom()) + lp.topMargin) + lp.bottomMargin) + heightUsed, lp.height, canScrollVertically());
if (shouldMeasureChild(child, widthSpec, heightSpec, lp)) {
child.measure(widthSpec, heightSpec);
}
}
示例13: bindLayoutView
import android.view.View; //导入方法依赖的package包/类
public void bindLayoutView(@NonNull final View layoutView) {
layoutView.measure(View.MeasureSpec.makeMeasureSpec(mLayoutRegion.width(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(mLayoutRegion.height(), View.MeasureSpec.EXACTLY));
layoutView.layout(mLayoutRegion.left, mLayoutRegion.top, mLayoutRegion.right, mLayoutRegion.bottom);
layoutView.setBackgroundColor(mBgColor);
if (mLayoutViewBindListener != null) {
mLayoutViewBindListener.onBind(layoutView, getLayoutHelper());
}
// reset region rectangle
mLayoutRegion.set(0, 0, 0, 0);
}
示例14: createRefreshableView
import android.view.View; //导入方法依赖的package包/类
/**
* 设置布局内容
*/
@Override
protected FrameLayout createRefreshableView(Context context, AttributeSet attrs) {
FrameLayout frameLayout = new FrameLayout(context);
View v = LayoutInflater.from(context).inflate(R.layout.activity_with_bottom_tab_content, null);
v.measure(View.MeasureSpec.AT_MOST, View.MeasureSpec.AT_MOST);
frameLayout.addView(v);
return frameLayout;
}
示例15: addViewHolder
import android.view.View; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void addViewHolder(int row, int column, int itemType) {
boolean createdNewView;
// need to add new one
ViewHolder viewHolder = mRecycler.popRecycledViewHolder(itemType);
createdNewView = viewHolder == null;
if (createdNewView) {
viewHolder = createViewHolder(itemType);
}
if (viewHolder == null) {
return;
}
// prepare view holder
viewHolder.setRowIndex(row);
viewHolder.setColumnIndex(column);
viewHolder.setItemType(itemType);
View view = viewHolder.getItemView();
view.setTag(R.id.tag_view_holder, viewHolder);
// add view to the layout
addView(view, 0);
// save and measure view holder
if (itemType == ViewHolderType.ITEM) {
mViewHolders.put(row, column, viewHolder);
if (createdNewView) {
// DO NOT REMOVE THIS!! Fix bug with request layout "requestLayout() improperly called"
mAdapter.onBindViewHolder(viewHolder, row, getBindColumn(column));
}
view.measure(
MeasureSpec.makeMeasureSpec(mManager.getColumnWidth(column), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(mManager.getRowHeight(row), MeasureSpec.EXACTLY));
refreshItemViewHolder(viewHolder);
if (!createdNewView) {
// DO NOT REMOVE THIS!! Fix bug with request layout "requestLayout() improperly called"
mAdapter.onBindViewHolder(viewHolder, row, getBindColumn(column));
}
} else if (itemType == ViewHolderType.ROW_HEADER) {
mHeaderRowViewHolders.put(row, viewHolder);
if (createdNewView) {
// DO NOT REMOVE THIS!! Fix bug with request layout "requestLayout() improperly called"
mAdapter.onBindHeaderRowViewHolder(viewHolder, row);
}
view.measure(
MeasureSpec.makeMeasureSpec(mManager.getHeaderRowWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(mManager.getRowHeight(row), MeasureSpec.EXACTLY));
refreshHeaderRowViewHolder(viewHolder);
if (!createdNewView) {
// DO NOT REMOVE THIS!! Fix bug with request layout "requestLayout() improperly called"
mAdapter.onBindHeaderRowViewHolder(viewHolder, row);
}
} else if (itemType == ViewHolderType.COLUMN_HEADER) {
mHeaderColumnViewHolders.put(column, viewHolder);
if (createdNewView) {
// DO NOT REMOVE THIS!! Fix bug with request layout "requestLayout() improperly called"
mAdapter.onBindHeaderColumnViewHolder(viewHolder, getBindColumn(column));
}
view.measure(
MeasureSpec.makeMeasureSpec(mManager.getColumnWidth(column), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(mManager.getHeaderColumnHeight(), MeasureSpec.EXACTLY));
refreshHeaderColumnViewHolder(viewHolder);
if (!createdNewView) {
// DO NOT REMOVE THIS!! Fix bug with request layout "requestLayout() improperly called"
mAdapter.onBindHeaderColumnViewHolder(viewHolder, getBindColumn(column));
}
}
}