Java Code Examples for android.view.ViewGroup#getMeasuredHeight()

The following examples show how to use android.view.ViewGroup#getMeasuredHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarView.java    From SlidePager with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: CenterLinearLayoutManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: CategoriesGridAdapter.java    From outlay with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example 4
Source File: ImageRow.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);
}
 
Example 5
Source File: FreeRadioGroup.java    From FreeRadioGroup with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example 6
Source File: BaseDialogFragment.java    From android-styled-dialogs with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: DimensionConverter.java    From DynamicLayoutInflator with MIT License 5 votes vote down vote up
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);
}
 
Example 8
Source File: ExplosionFragment.java    From Backboard with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: MDRootLayout.java    From talk-android with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: BaseDialogFragment.java    From AndroidTabbedDialog with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: GridCalendarAdapter.java    From NCalendar with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 12
Source File: FirstActivity.java    From boxing with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 13
Source File: ContactListAdapter.java    From beauty-treatment-android-animations with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example 14
Source File: DimensionConverter.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: VideoPopWindow.java    From QSVideoPlayer with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 16
Source File: DimensionConverter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 17
Source File: MainActivity.java    From CameraBlur with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 18
Source File: StickerModel.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example 19
Source File: CenterLinearLayoutManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 20
Source File: BaseHolder.java    From recyclerview-multistate-section-endless-adapter with Apache License 2.0 4 votes vote down vote up
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());
  }
}