android.view.ViewGroup#getMeasuredHeight ( )源码实例Demo

下面列出了android.view.ViewGroup#getMeasuredHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ProjectX   文件: CenterLinearLayoutManager.java
@Override
public void layoutDecorated(@NonNull View child, int left, int top, int right, int bottom) {
    if (!mCenter) {
        super.layoutDecorated(child, left, top, right, bottom);
        return;
    }
    final int leftDecorationWidth = getLeftDecorationWidth(child);
    final int topDecorationHeight = getTopDecorationHeight(child);
    final int rightDecorationWidth = getRightDecorationWidth(child);
    final int bottomDecorationHeight = getBottomDecorationHeight(child);
    final ViewGroup parent = (ViewGroup) child.getParent();
    final int offset;
    if (getOrientation() == HORIZONTAL) {
        final int contentHeight = parent.getMeasuredHeight() -
                parent.getPaddingTop() - parent.getPaddingBottom();
        offset = (contentHeight - (bottom - top)) / 2;
        child.layout(left + leftDecorationWidth, top + topDecorationHeight + offset,
                right - rightDecorationWidth, bottom - bottomDecorationHeight + offset);
    } else {
        final int contentWidth = parent.getMeasuredWidth() -
                parent.getPaddingLeft() - parent.getPaddingRight();
        offset = (contentWidth - (right - left)) / 2;
        child.layout(left + leftDecorationWidth + offset, top + topDecorationHeight,
                right - rightDecorationWidth + offset, bottom - bottomDecorationHeight);
    }
}
 
源代码2 项目: dhis2-android-capture-app   文件: ImageRow.java
public ImageHolder onCreate(@NonNull ViewGroup parent, int count, FlowableProcessor<String> imageSelector) {
    FormImageBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.form_image, parent, false);
    Integer height = null;
    if (renderType.equals(ProgramStageSectionRenderingType.SEQUENTIAL.name())) {
        height = parent.getMeasuredHeight() / (count > 2 ? 3 : count);
    } else if (renderType.equals(ProgramStageSectionRenderingType.MATRIX.name())) {
        height = parent.getMeasuredHeight() / (count > 2 ? 2 : count);
    }

    View rootView = binding.getRoot();
    if (height != null) {
        ViewGroup.LayoutParams layoutParams = rootView.getLayoutParams();
        layoutParams.height = height;
        rootView.setLayoutParams(layoutParams);
    }

    return new ImageHolder(binding, processor, isBackgroundTransparent, renderType, rootView, imageSelector);
}
 
源代码3 项目: FreeRadioGroup   文件: FreeRadioGroup.java
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    if (moveable) {
        ViewGroup parentView = ((ViewGroup) getParent());
        MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
        viewWidth = getRight() - getLeft();
        viewHight = getBottom() - getTop();
        parentWidth = parentView.getMeasuredWidth();
        parentHeight = parentView.getMeasuredHeight();
        minLeftMargin = lp.leftMargin;
        leftPadding = parentView.getPaddingLeft();
        rightDistance = lp.rightMargin + parentView.getPaddingRight();
        maxLeftMargin = parentWidth - rightDistance - viewWidth - leftPadding;
        minTopMargin = lp.topMargin;
        topPadding = parentView.getPaddingTop();
        bottomDistance = lp.bottomMargin + parentView.getPaddingBottom();
        maxTopMargin = parentHeight - bottomDistance - viewHight - topPadding;
    }
}
 
源代码4 项目: outlay   文件: CategoriesGridAdapter.java
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    switch (viewType) {
        case HEADER:
            final View numpadView = inflater.inflate(app.outlay.R.layout.recycler_numpad, parent, false);
            GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) numpadView.getLayoutParams();
            params.height = parent.getMeasuredHeight() - (context.getResources().getDimensionPixelSize(app.outlay.R.dimen.category_item_height) * 2);

            final NumpadViewHolder viewHolder = new NumpadViewHolder(numpadView);
            return viewHolder;
        default:
            final View catView = inflater.inflate(app.outlay.R.layout.item_category, parent, false);
            final CategoryViewHolder categoryViewHolder = new CategoryViewHolder(catView);
            return categoryViewHolder;
    }
}
 
源代码5 项目: SlidePager   文件: BarView.java
/**
 * Animate the change in progress of this view
 *
 * @param end      The value to set it to, between 0-100, if -1, there is no bar for null value, otherwise
 *                 a circle will be animated.
 * @param duration The the time to run the animation over,
 */
public void animateProgress(int end, int duration, int delay) {
    mProgress = end;

    ViewGroup parent = (ViewGroup) getParent();
    int heightToReach = (parent.getMeasuredHeight() * end) / 102;
    int initialHeight = (int) mBarWidth;
    heightToReach = (heightToReach < initialHeight) ? initialHeight : heightToReach;
    if (end == -1) {
        heightToReach = 0;
    }
    setVisibility(View.INVISIBLE);
    setPivotY(heightToReach);
    setMinimumHeight(heightToReach);
    AnimatorSet set = new AnimatorSet();
    setVisibility(VISIBLE);
    set.playTogether(Glider.glide(Skill.BounceEaseOut, duration, ObjectAnimator.ofFloat(this, "scaleY", 0, 1)));
    set.setDuration(duration);
    set.setStartDelay(delay);
    set = addListenersToSet(set);
    set.start();
}
 
源代码6 项目: ProjectX   文件: CenterLinearLayoutManager.java
@Override
public void layoutDecoratedWithMargins(@NonNull View child, int left, int top, int right, int bottom) {
    if (!mCenter) {
        super.layoutDecoratedWithMargins(child, left, top, right, bottom);
        return;
    }
    final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
    final int leftDecorationWidth = getLeftDecorationWidth(child);
    final int topDecorationHeight = getTopDecorationHeight(child);
    final int rightDecorationWidth = getRightDecorationWidth(child);
    final int bottomDecorationHeight = getBottomDecorationHeight(child);
    final ViewGroup parent = (ViewGroup) child.getParent();
    final int offset;
    if (getOrientation() == RecyclerView.HORIZONTAL) {
        final int contentHeight = parent.getMeasuredHeight() -
                parent.getPaddingTop() - parent.getPaddingBottom();
        offset = (contentHeight - (bottom - top)) / 2;
        child.layout(left + leftDecorationWidth + lp.leftMargin,
                top + topDecorationHeight + lp.topMargin + offset,
                right - rightDecorationWidth - lp.rightMargin,
                bottom - bottomDecorationHeight - lp.bottomMargin + offset);
    } else {
        final int contentWidth = parent.getMeasuredWidth() -
                parent.getPaddingLeft() - parent.getPaddingRight();
        offset = (contentWidth - (right - left)) / 2;
        child.layout(left + leftDecorationWidth + offset + lp.leftMargin,
                top + topDecorationHeight + lp.topMargin,
                right - rightDecorationWidth - lp.rightMargin + offset,
                bottom - bottomDecorationHeight - lp.bottomMargin);
    }
}
 
private boolean isScrollable(ViewGroup listView) {
    int totalHeight = 0;
    for (int i = 0; i < listView.getChildCount(); i++) {
        totalHeight += listView.getChildAt(i).getMeasuredHeight();
    }
    return listView.getMeasuredHeight() < totalHeight;
}
 
源代码8 项目: EasyPhotos   文件: StickerModel.java
private void setSize(Bitmap b, ViewGroup v) {
        int bW = b.getWidth();
        int bH = b.getHeight();

        int vW = v.getMeasuredWidth();
        int vH = v.getMeasuredHeight();

        float scalW = (float) vW / (float) bW;
        float scalH = (float) vH / (float) bH;

        ViewGroup.LayoutParams params = v.getLayoutParams();
        //如果图片小于viewGroup的宽高则把viewgroup设置为图片宽高
//        if (bW < vW && bH < vH) {
//            params.width = bW;
//            params.height = bH;
//            v.setLayoutParams(params);
//            return;
//        }
        if (bW >= bH) {
            params.width = vW;
            params.height = (int) (scalW * bH);
        } else {
            params.width = (int) (scalH * bW);
            params.height = vH;
        }
        if (params.width > vW) {
            float tempScaleW = (float) vW / (float) params.width;
            params.width = vW;
            params.height = (int) (params.height * tempScaleW);
        }
        if (params.height > vH) {
            float tempScaleH = (float) vH / (float) params.height;
            params.height = vH;
            params.width = (int) (params.width * tempScaleH);
        }
        v.setLayoutParams(params);
    }
 
源代码9 项目: CameraBlur   文件: MainActivity.java
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false);
    if(parent.getMeasuredHeight()>parent.getMeasuredWidth()) {
        viewHeight =(int)((parent.getMeasuredWidth()/spanCount)*4*1.0/3);
    }
    else  viewHeight =(int)((parent.getMeasuredWidth()/spanCount)*4*1.0/3);
    return new ViewHolder(view);
}
 
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);
}
 
源代码11 项目: QSVideoPlayer   文件: VideoPopWindow.java
public VideoPopWindow(Context context, List<QSVideo> qsVideos, int index) {
    ViewGroup popview = (ViewGroup) LayoutInflater.from(context).inflate(
            R.layout.pop_definition, new FrameLayout(context), false);
    float density = context.getResources().getDisplayMetrics().density;
    int padding = (int) (density * 12);
    for (int i = 0; i < qsVideos.size(); i++) {
        QSVideo qsVideo = qsVideos.get(i);
        TextView textView = new TextView(context);
        textView.setId(i);
        textView.setPadding(padding, padding / 2, padding, padding / 2);
        textView.setText(qsVideo.resolution());
        textView.setTextSize(14);
        textView.setOnClickListener(this);
        textView.setTextColor(index == i ? context.getResources().getColor(R.color.colorMain) : 0xffffffff);
        popview.addView(textView);
    }
    int mode = View.MeasureSpec.AT_MOST;
    //手动调用计算宽高
    popview.measure(View.MeasureSpec.makeMeasureSpec(1080, mode),
            View.MeasureSpec.makeMeasureSpec(1920, mode));
    h = popview.getMeasuredHeight();
    //设置视图
    setContentView(popview);
    setWidth(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);//设置宽
    setHeight(android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);//设置高
    setFocusable(true);
    setOutsideTouchable(true);
    // 刷新状态
    update();
    // 实例化一个ColorDrawable颜色为半透明
    ColorDrawable dw = new ColorDrawable(0);
    // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
    setBackgroundDrawable(dw);
}
 
源代码12 项目: javaide   文件: DimensionConverter.java
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);
}
 
private View createFooterView(ViewGroup parent) {

        int screenHeight = parent.getMeasuredHeight();
        int itemHeight = (int) parent.getContext().getResources().getDimension(R.dimen.recyclerview_item_height);

        View view = new View(parent.getContext());
        parent.addView(view);

        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height = screenHeight - itemHeight;
        view.setLayoutParams(lp);

        return view;
    }
 
源代码14 项目: boxing   文件: FirstActivity.java
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_boxing_simple_media_item, parent, false);
    int height = parent.getMeasuredHeight() / 4;
    view.setMinimumHeight(height);
    return new MediaViewHolder(view);
}
 
源代码15 项目: NCalendar   文件: GridCalendarAdapter.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View calendarItemView = viewList.get(position);
    int realHeight = parent.getMeasuredHeight() - parent.getPaddingBottom() - parent.getPaddingTop();
    AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, realHeight / (viewList.size() / 7));
    calendarItemView.setLayoutParams(params);
    ((CalendarView2) parent).bindView(position, calendarItemView);
    return calendarItemView;
}
 
源代码16 项目: AndroidTabbedDialog   文件: BaseDialogFragment.java
private boolean isScrollable(ViewGroup listView) {
    int totalHeight = 0;
    for (int i = 0; i < listView.getChildCount(); i++) {
        totalHeight += listView.getChildAt(i).getMeasuredHeight();
    }
    return listView.getMeasuredHeight() < totalHeight;
}
 
源代码17 项目: talk-android   文件: MDRootLayout.java
/**
 * Find the view touching the bottom of this ViewGroup. Non visible children are ignored,
 * however getChildDrawingOrder is not taking into account for simplicity and because it behaves
 * inconsistently across platform versions.
 *
 * @return View touching the bottom of this ViewGroup or null
 */
@Nullable
private static View getBottomView(ViewGroup viewGroup) {
    if (viewGroup == null || viewGroup.getChildCount() == 0)
        return null;
    View bottomView = null;
    for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
        View child = viewGroup.getChildAt(i);
        if (child.getVisibility() == View.VISIBLE && child.getBottom() == viewGroup.getMeasuredHeight()) {
            bottomView = child;
            break;
        }
    }
    return bottomView;
}
 
源代码18 项目: Backboard   文件: ExplosionFragment.java
private static void createCircle(Context context, ViewGroup rootView,
                                 SpringSystem springSystem,
                                 SpringConfig coasting,
                                 SpringConfig gravity,
                                 int diameter,
                                 Drawable backgroundDrawable) {

	final Spring xSpring = springSystem.createSpring().setSpringConfig(coasting);
	final Spring ySpring = springSystem.createSpring().setSpringConfig(gravity);

	// create view
	View view = new View(context);

	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(diameter, diameter);
	params.addRule(RelativeLayout.CENTER_IN_PARENT);
	view.setLayoutParams(params);
	view.setBackgroundDrawable(backgroundDrawable);

	rootView.addView(view);

	// generate random direction and magnitude
	double magnitude = Math.random() * 1000 + 3000;
	double angle = Math.random() * Math.PI / 2 + Math.PI / 4;

	xSpring.setVelocity(magnitude * Math.cos(angle));
	ySpring.setVelocity(-magnitude * Math.sin(angle));

	int maxX = rootView.getMeasuredWidth() / 2 + diameter;
	xSpring.addListener(new Destroyer(rootView, view, -maxX, maxX));

	int maxY = rootView.getMeasuredHeight() / 2 + diameter;
	ySpring.addListener(new Destroyer(rootView, view, -maxY, maxY));

	xSpring.addListener(new Performer(view, View.TRANSLATION_X));
	ySpring.addListener(new Performer(view, View.TRANSLATION_Y));

	// set a different end value to cause the animation to play
	xSpring.setEndValue(2);
	ySpring.setEndValue(9001);
}
 
源代码19 项目: DynamicLayoutInflator   文件: DimensionConverter.java
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);
}
 
public BaseHolder(LayoutInflater inflater, ViewGroup parent, @LayoutRes int layoutId, boolean isFillParent) {
  super(inflate(inflater, parent, layoutId));
  if (isFillParent && parent != null) {
    getItemView().getLayoutParams().height = parent.getMeasuredHeight() - (parent.getPaddingTop() + parent.getPaddingBottom());
  }
}
 
 方法所在类