当前位置: 首页>>代码示例>>Java>>正文


Java View.resolveSizeAndState方法代码示例

本文整理汇总了Java中android.view.View.resolveSizeAndState方法的典型用法代码示例。如果您正苦于以下问题:Java View.resolveSizeAndState方法的具体用法?Java View.resolveSizeAndState怎么用?Java View.resolveSizeAndState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.View的用法示例。


在下文中一共展示了View.resolveSizeAndState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMeasure

import android.view.View; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);

    // General goal: Adjust dimensions to maintain the requested aspect ratio as much
    // as possible. Depending on the measure specs handed down, this may not be possible

    // Only set one of these to true
    boolean scaleWidth = false;
    boolean scaleHeight = false;

    // Sort out which dimension to scale, if either can be. There are 9 combinations of
    // possible measure specs; a few cases below handle multiple combinations
    if (widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY) {
        // Can't adjust sizes at all, do nothing
    } else if (widthMode == MeasureSpec.EXACTLY) {
        // Width is fixed, heightMode either AT_MOST or UNSPECIFIED, so adjust height
        scaleHeight = true;
    } else if (heightMode == MeasureSpec.EXACTLY) {
        // Height is fixed, widthMode either AT_MOST or UNSPECIFIED, so adjust width
        scaleWidth = true;
    } else if (widthMode == MeasureSpec.AT_MOST && heightMode == MeasureSpec.AT_MOST) {
        // Need to fit into box <= [width, height] in size.
        // Maximize the View's area while maintaining aspect ratio
        // This means keeping one dimension as large as possible and shrinking the other
        float boxAspectRatio = width / (float) height;
        if (boxAspectRatio > mAspectRatio) {
            // Box is wider than requested aspect; pillarbox
            scaleWidth = true;
        } else {
            // Box is narrower than requested aspect; letterbox
            scaleHeight = true;
        }
    } else if (widthMode == MeasureSpec.AT_MOST) {
        // Maximize width, heightSpec is UNSPECIFIED
        scaleHeight = true;
    } else if (heightMode == MeasureSpec.AT_MOST) {
        // Maximize height, widthSpec is UNSPECIFIED
        scaleWidth = true;
    } else {
        // Both MeasureSpecs are UNSPECIFIED. This is probably a pathological layout,
        // with width == height == 0
        // but arbitrarily scale height anyway
        scaleHeight = true;
    }

    // Do the scaling
    if (scaleWidth) {
        width = (int) (height * mAspectRatio);
    } else if (scaleHeight) {
        height = (int) (width / mAspectRatio);
    }

    // Override width/height if needed for EXACTLY and AT_MOST specs
    width = View.resolveSizeAndState(width, widthMeasureSpec, 0);
    height = View.resolveSizeAndState(height, heightMeasureSpec, 0);

    // Finally set the calculated dimensions
    setMeasuredDimension(width, height);
}
 
开发者ID:lydia-schiff,项目名称:hella-renderscript,代码行数:65,代码来源:FixedAspectSurfaceView.java

示例2: resolveSizeAndState

import android.view.View; //导入方法依赖的package包/类
@Override
public int resolveSizeAndState(int size, int measureSpec, int state) {
    return View.resolveSizeAndState(size, measureSpec, state);
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:5,代码来源:Utility11.java

示例3: resolveSizeAndState

import android.view.View; //导入方法依赖的package包/类
public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    return View.resolveSizeAndState(size, measureSpec, childMeasuredState);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:4,代码来源:ViewCompatHC.java


注:本文中的android.view.View.resolveSizeAndState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。