本文整理汇总了Java中android.view.ViewGroup.getMeasuredWidth方法的典型用法代码示例。如果您正苦于以下问题:Java ViewGroup.getMeasuredWidth方法的具体用法?Java ViewGroup.getMeasuredWidth怎么用?Java ViewGroup.getMeasuredWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.ViewGroup
的用法示例。
在下文中一共展示了ViewGroup.getMeasuredWidth方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLayoutParams
import android.view.ViewGroup; //导入方法依赖的package包/类
/**
* 创建一个layout params,并不能改变view的大小
*
* @param container
* @return
*/
private RelativeLayout.LayoutParams createLayoutParams(ViewGroup container) {
final RelativeLayout.LayoutParams layoutParams = LuaViewUtil.createRelativeLayoutParamsWM();
if(container != null) {
layoutParams.width = container.getMeasuredWidth();
layoutParams.height = container.getMeasuredHeight();
}
return layoutParams;
}
示例2: stringToDimensionPixelSize
import android.view.ViewGroup; //导入方法依赖的package包/类
public static int stringToDimensionPixelSize(String dimension, DisplayMetrics metrics, ViewGroup parent, boolean horizontal) {
if (dimension.endsWith("%")) {
float pct = Float.parseFloat(dimension.substring(0, dimension.length() - 1)) / 100.0f;
return (int) (pct * (horizontal ? parent.getMeasuredWidth() : parent.getMeasuredHeight()));
}
return stringToDimensionPixelSize(dimension, metrics);
}
示例3: onMeasure
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!allowWidthFull)
return;
ViewGroup tabsLayout = getTabsLayout();
if (tabsLayout == null
|| tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
return;
if (tabsLayout.getChildCount() <= 0)
return;
if (tabViews == null) {
tabViews = new ArrayList<View>();
} else {
tabViews.clear();
}
for (int w = 0; w < tabsLayout.getChildCount(); w++) {
tabViews.add(tabsLayout.getChildAt(w));
}
adjustChildWidthWithParent(
tabViews,
getMeasuredWidth() - tabsLayout.getPaddingLeft()
- tabsLayout.getPaddingRight(), widthMeasureSpec,
heightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
示例4: onCreateViewHolder
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.parent_item, parent, false);
MyViewHolder holder = new MyViewHolder(view);
parentWidth = parent.getMeasuredWidth();
itemWidth = (parentWidth -
(holder.textView.getPaddingLeft() + holder.textView.getPaddingRight()) * (GROUPS_COLUMN_COUNT))
/ GROUPS_COLUMN_COUNT + 1;
return holder;
}
示例5: onCreateViewHolder
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.child_item, parent, false);
MyViewHolder holder = new MyViewHolder(view);
parentWidth = parent.getMeasuredWidth();
itemWidth = (parentWidth -
(holder.textView.getPaddingLeft() + holder.textView.getPaddingRight()) * (EPISODES_COLUMN_COUNT))
/ EPISODES_COLUMN_COUNT + 1;
return holder;
}
示例6: calculateDistanceToFinalSnap
import android.view.ViewGroup; //导入方法依赖的package包/类
@Nullable
@Override
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) targetView.getLayoutParams();
int position = params.getViewAdapterPosition();
int left = targetView.getLeft();
int right = targetView.getRight();
int top = targetView.getTop();
int bottom = targetView.getBottom();
ViewGroup viewGroup = (ViewGroup) targetView.getParent();
int[] out = new int[]{0, 0};
boolean isLastItem;
if (mOrientation == LinearLayoutManager.HORIZONTAL) {
isLastItem = position == layoutManager.getItemCount() - 1/*最后一个*/ && right == viewGroup.getMeasuredWidth();
out[0] = left;
out[1] = 0;
} else {
isLastItem = position == layoutManager.getItemCount() - 1/*最后一个*/ && bottom == viewGroup.getMeasuredHeight();
out[0] = 0;
out[1] = top;
}
if (mOnPageListener != null && mCurrentPosition != position) {
int currentPosition = mCurrentPosition;
boolean listener = false;
if (mOrientation == LinearLayoutManager.HORIZONTAL && (out[0] == 0 || isLastItem)) {
listener = true;
} else if (mOrientation == LinearLayoutManager.VERTICAL && (out[1] == 0 || isLastItem)) {
listener = true;
}
if (listener) {
mCurrentPosition = position;
mOnPageListener.onPageSelector(mCurrentPosition);
mOnPageListener.onPageSelector(currentPosition, mCurrentPosition);
}
}
return out;
}
示例7: onCreateViewHolder
import android.view.ViewGroup; //导入方法依赖的package包/类
public void onCreateViewHolder(ViewGroup parent, View itemView) {
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) itemView.getLayoutParams();
lp.width = parent.getMeasuredWidth() - UiUtils.dip2px(itemView.getContext(), 2 * (mPagePadding + mShowLeftCardWidth));
itemView.setLayoutParams(lp);
}
示例8: onCreateViewHolder
import android.view.ViewGroup; //导入方法依赖的package包/类
@Override
public MenuNavItem onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_nav_item, parent, false);
v.getLayoutParams().width = parent.getMeasuredWidth() / navItems.size();
return new MenuNavItem(v);
}
示例9: updateInElevator
import android.view.ViewGroup; //导入方法依赖的package包/类
private void updateInElevator() {
ViewParent parent = getParent();
if (!(parent instanceof ViewGroup)) {
return;
}
ViewGroup parentView = (ViewGroup) parent;
Resources res = getResources();
float mySize = res.getDimension(R.dimen.person_size);
float speed = mySize / TIME_TO_STEP; // pixels per ms
float baseLineX = res.getDimension(R.dimen.elevator_doors_width); // x values start right after elevator doors
int parentWidth = parentView.getMeasuredWidth();
int parentHeight = parentView.getMeasuredHeight();
float centerY = (parentHeight - mySize) / 2.0f;
switch (person.getCurrentState()) {
case IN_DOOR:
setY(centerY);
float traverseDoorsDistance = getTraverseDoorsDistance();
if (person.hasReachedGoal()) {
// exiting elevator
moveX(speed, baseLineX, -traverseDoorsDistance);
} else {
// entering elevator
float enterProgress = moveX(speed, baseLineX - traverseDoorsDistance, traverseDoorsDistance);
if (enterProgress == 1) {
person.setCurrentState(ELEVATOR_PRE_PRESS);
}
}
break;
case ELEVATOR_PRE_PRESS:
setX(baseLineX);
float distanceToPanel = res.getDimension(R.dimen.elevator_panel_offset) + res.getDimension(R.dimen.elevator_panel_size) / 2;
float panelProgress = moveY(speed, centerY, distanceToPanel);
if (panelProgress == 1) {
person.setCurrentState(ELEVATOR_POST_PRESS);
}
break;
case ELEVATOR_POST_PRESS:
float startPanel = centerY + res.getDimension(R.dimen.elevator_panel_offset)
+ res.getDimension(R.dimen.elevator_panel_size) / 2;
float progress = moveXY(speed, baseLineX, startPanel,
parentWidth * preferredX - baseLineX,
parentHeight * preferredY - startPanel);
if (progress == 1 && person.hasReachedGoal()) {
person.setCurrentState(ELEVATOR_GOAL_FLOOR);
}
break;
case ELEVATOR_GOAL_FLOOR:
float progressTowardDoor = moveXY(speed, parentWidth * preferredX, parentHeight * preferredY,
baseLineX - parentWidth * preferredX,
centerY - parentHeight * preferredY);
if (progressTowardDoor == 1 && person.hasReachedGoal() && doorsOpen.getValue()) {
person.setCurrentState(IN_DOOR);
}
break;
}
}
示例10: onCreateViewHolder
import android.view.ViewGroup; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public DefaultAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
TabTextView tabTextView = new TabTextView(parent.getContext());
if (mTabSelectedTextColorSet) {
tabTextView.setTextColor(tabTextView.createColorStateList(
tabTextView.getCurrentTextColor(), mTabSelectedTextColor));
}
ViewCompat.setPaddingRelative(tabTextView, mTabPaddingStart, mTabPaddingTop,
mTabPaddingEnd, mTabPaddingBottom);
tabTextView.setTextAppearance(parent.getContext(), mTabTextAppearance);
tabTextView.setGravity(Gravity.CENTER);
tabTextView.setMaxLines(MAX_TAB_TEXT_LINES);
tabTextView.setEllipsize(TextUtils.TruncateAt.END);
if (mTabOnScreenLimit > 0) {
int width = parent.getMeasuredWidth() / mTabOnScreenLimit;
tabTextView.setMaxWidth(width);
tabTextView.setMinWidth(width);
} else {
if (mTabMaxWidth > 0) {
tabTextView.setMaxWidth(mTabMaxWidth);
}
tabTextView.setMinWidth(mTabMinWidth);
}
tabTextView.setTextAppearance(tabTextView.getContext(), mTabTextAppearance);
if (mTabSelectedTextColorSet) {
tabTextView.setTextColor(tabTextView.createColorStateList(
tabTextView.getCurrentTextColor(), mTabSelectedTextColor));
}
if (mTabBackgroundResId != 0) {
tabTextView.setBackgroundDrawable(
AppCompatResources.getDrawable(tabTextView.getContext(), mTabBackgroundResId));
}
tabTextView.setLayoutParams(createLayoutParamsForTabs());
return new ViewHolder(tabTextView);
}
示例11: show
import android.view.ViewGroup; //导入方法依赖的package包/类
public void show(Context content,View locationView,String[] menuLabelArray,OnPopMultiMenuClick onPopMultiMenuClick){
try {
//check
if(menuLabelArray==null || menuLabelArray.length<1){
throw new RuntimeException(" menu label can not be empty ");
}
// ready
LayoutInflater layoutInflater=LayoutInflater.from(content);
mOnPopMultiMenuClick = onPopMultiMenuClick;
// 如果只有一个,则把divider删除掉
ViewGroup popupView =(ViewGroup) layoutInflater.inflate(R.layout.udesk_multi_horizontal_popmenu, null);
// 把菜单都添加进去
addChildView(popupView,layoutInflater,menuLabelArray);
setContentView(popupView);
// 测绘并定位
popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
int popupWidth = popupView.getMeasuredWidth();
int popupHeight = popupView.getMeasuredHeight();
setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
setHeight(popupHeight);
//显示出来
int[] location = new int[2];
locationView.getLocationOnScreen(location);
showAtLocation(locationView, Gravity.NO_GRAVITY , /*location[0]*/(location[0]+locationView.getWidth()/2)-popupWidth/2,
location[1]-popupHeight/*location[1]- getHeight()*/);
} catch (RuntimeException e) {
e.printStackTrace();
}
}