resolve View desired Size - Android User Interface

Android examples for User Interface:View Size

Description

resolve View desired Size

Demo Code


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

public class Main {
    public static int resolveSize(int desiredSize, int maxSize, int mode) {
        int suggestMode = View.MeasureSpec.getMode(mode);
        int suggestSize = View.MeasureSpec.getSize(mode);

        int result = desiredSize;
        switch (suggestMode) {
        case View.MeasureSpec.UNSPECIFIED:
            result = Math.min(desiredSize, maxSize);
            break;
        case View.MeasureSpec.AT_MOST:
            result = Math.min(Math.min(desiredSize, maxSize), suggestSize);
            break;
        case View.MeasureSpec.EXACTLY:
            result = suggestSize;//  ww  w. ja v  a 2  s  .c  om
            break;
        }
        return result;
    }
}

Related Tutorials