Example usage for android.widget TableLayout getMeasuredHeight

List of usage examples for android.widget TableLayout getMeasuredHeight

Introduction

In this page you can find the example usage for android.widget TableLayout getMeasuredHeight.

Prototype

public final int getMeasuredHeight() 

Source Link

Document

Like #getMeasuredHeightAndState() , but only returns the raw height component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:at.ac.uniklu.mobile.sportal.DashboardUpcomingDatesFragment.java

private void adjustDateListHeight() {
    final TableLayout dateListTable = (TableLayout) getView().findViewById(R.id.dates);
    // post the action to the UI thread to defer execution until the view has been drawn
    dateListTable.post(new Runnable() {
        @Override//w  w  w.j  av a  2s.c o m
        public void run() {
            // get first row
            View v = dateListTable.getChildAt(0);
            int entryHeight;
            if (v != null && (entryHeight = v.getMeasuredHeight()) > 0) {
                int numPossibleVisibleRows = dateListTable.getMeasuredHeight() / entryHeight;
                int numExisitingRows = Math.min(numPossibleVisibleRows, dateListTable.getChildCount());
                int numVisibleRows = Math.min(numExisitingRows, numPossibleVisibleRows);
                // remove rows that are outside the screen
                if (numExisitingRows > numVisibleRows) {
                    dateListTable.removeViews(numVisibleRows, numExisitingRows - numVisibleRows);
                }
                // toggle visibility of rows inside the screen
                for (int x = 0; x < numVisibleRows; x++) {
                    dateListTable.getChildAt(x).setVisibility(View.VISIBLE);
                }
            } else {
                Log.d(TAG, "cannot adjust list height");
            }
        }
    });
}