resolve Size And State from View.MeasureSpec - Android User Interface

Android examples for User Interface:View Size

Description

resolve Size And State from View.MeasureSpec

Demo Code


//package com.java2s;
import android.view.View;
import android.view.View.MeasureSpec;

public class Main {
    private static int resolveSizeAndState(int size, int measureSpec,
            int childMeasuredState) {
        int result = size;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);
        switch (specMode) {
        case MeasureSpec.UNSPECIFIED:
            result = size;// w w  w.  ja  va  2  s . co m
            break;
        case MeasureSpec.AT_MOST:
            if (specSize < size) {
                result = specSize | View.MEASURED_STATE_TOO_SMALL;
            } else {
                result = size;
            }
            break;
        case MeasureSpec.EXACTLY:
            result = specSize;
            break;
        }
        return result | (childMeasuredState & View.MEASURED_STATE_MASK);
    }
}

Related Tutorials