Example usage for android.widget ScrollView requestLayout

List of usage examples for android.widget ScrollView requestLayout

Introduction

In this page you can find the example usage for android.widget ScrollView requestLayout.

Prototype

@Override
    public void requestLayout() 

Source Link

Usage

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void setDetailScrollViewHeight() {
    final Point displaySize = UIUtils.getDisplaySize(mActivity);
    final TextView nameLbl = (TextView) mDetailDialog.findViewById(R.id.name);
    final TextView priceLbl = (TextView) mDetailDialog.findViewById(R.id.price);
    final ScrollView scrollView = (ScrollView) mDetailDialog.findViewById(R.id.scroll_view);
    final LinearLayout valueContainer = (LinearLayout) mDetailDialog.findViewById(R.id.value_container);
    final Button dismissBtn = (Button) mDetailDialog.findViewById(R.id.dismiss);
    int maxPopupHeight = (int) Math.floor(displaySize.y * 0.75);

    int desiredWidth = MeasureSpec.makeMeasureSpec(nameLbl.getWidth(), MeasureSpec.AT_MOST);

    nameLbl.measure(desiredWidth, 0);// w  ww .j a  va 2s.co  m
    int nameLblHeight = nameLbl.getMeasuredHeight();
    int priceLblHeight = 0;
    if (priceLbl.getVisibility() == View.VISIBLE) {
        priceLbl.measure(desiredWidth, 0);
        priceLblHeight = priceLbl.getMeasuredHeight();
    }
    valueContainer.measure(desiredWidth, 0);
    int valueContainerHeight = valueContainer.getMeasuredHeight();
    dismissBtn.measure(desiredWidth, 0);
    int dismissBtnHeight = dismissBtn.getMeasuredHeight();

    int maxScrollViewHeight = maxPopupHeight - nameLblHeight - priceLblHeight - valueContainerHeight
            - dismissBtnHeight;

    ViewGroup.LayoutParams params = scrollView.getLayoutParams();
    scrollView.measure(desiredWidth, 0);
    params.height = scrollView.getMeasuredHeight();
    if (maxScrollViewHeight > 0 && params.height > maxScrollViewHeight) {
        params.height = maxScrollViewHeight;
    }
    scrollView.setLayoutParams(params);
    scrollView.requestLayout();
}