launcher3 修改文件夹图标九宫格显示

res/layout/folder_icon.xml:        android:src=”@drawable/icon_bg_6″/>     换个方形的背景

packages\apps\Launcher3\src\com\android\launcher3\FolderIcon.java

    private PreviewItemDrawingParams computePreviewItemDrawingParams(int index,
            PreviewItemDrawingParams params) {
// add by x
int index_order = index;
final int previewPadding = FolderRingAnimator.sPreviewPadding;
// add end
        index = NUM_ITEMS_IN_PREVIEW – index – 1;
        float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW – 1);
        float scale = (1 – PERSPECTIVE_SCALE_FACTOR * (1 – r));
        float offset = (1 – r) * mMaxPerspectiveShift;
        float scaledSize = scale * mBaselineIconSize;
        float scaleOffsetCorrection = (1 – scale) * mBaselineIconSize;
        // We want to imagine our coordinates from the bottom left, growing up and to the
        // right. This is natural for the x-axis, but for the y-axis, we have to invert things.
        float transY = mAvailableSpaceInPreview – (offset + scaledSize + scaleOffsetCorrection) + getPaddingTop();
        float transX = offset + scaleOffsetCorrection;
        float totalScale = mBaselineIconScale * scale;
        final int overlayAlpha = (int) (80 * (1 – r));

// add by x
if( PERSPECTIVE_SHIFT_FACTOR ==0.24f){

}else{
if(0 <= index_order&&index_order < 3){ // 0 1 2 
transX=index_order*mBaselineIconSize + 1*previewPadding;
transY=mAvailableSpaceInPreview – (2*mBaselineIconSize + scaledSize + scaleOffsetCorrection) + getPaddingTop()+0.2f*mBaselineIconSize;

}else if(3 <= index_order&&index_order < 6){ // 3 4 5 
transX=(index_order-3)*mBaselineIconSize + 1*previewPadding;
//transY=1*mBaselineIconSize+9*previewPadding;
transY=mAvailableSpaceInPreview – (1*mBaselineIconSize + scaledSize + scaleOffsetCorrection) + getPaddingTop()+0.2f*mBaselineIconSize;
}else if(6 <= index_order&&index_order < 9){ // 6 7 8 
transX=(index_order-6)*mBaselineIconSize + 1*previewPadding;
//transY=2*mBaselineIconSize+9*previewPadding;
transY=mAvailableSpaceInPreview – (0*mBaselineIconSize + scaledSize + scaleOffsetCorrection) + getPaddingTop()+0.2f*mBaselineIconSize;
}
totalScale = mBaselineIconScale * 1 – 0.1f;
}
//add end


        if (params == null) {
            params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha);
        } else {
            params.transX = transX;
            params.transY = transY;
            params.scale = totalScale ;
            params.overlayAlpha = overlayAlpha;
        }
        return params;
    }

    // The number of icons to display in the
    private static final int NUM_ITEMS_IN_PREVIEW = 4;     // 显示的个数

    // The amount of vertical spread between items in the stack [0…1]
    private static final float PERSPECTIVE_SHIFT_FACTOR = 1.59f;//1.59f //0.24f     //控制文件夹内的子图标大小,值越大,图标越小

    因为这个值关系到 mBaselineIconSize ,如下

    

private void computePreviewDrawingParams(int drawableSize, int totalSize) {

            int unscaledHeight = (int) (mIntrinsicIconSize * (1 + PERSPECTIVE_SHIFT_FACTOR));
            mBaselineIconScale = (1.0f * adjustedAvailableSpace / unscaledHeight);
            mBaselineIconSize = (int) (mIntrinsicIconSize * mBaselineIconScale);

}

    @Override
    protected void dispatchDraw(Canvas canvas) {

~         // 显示子图标的 顺序

        int nItemsInPreview = Math.min(items.size(), NUM_ITEMS_IN_PREVIEW);
        if (!mAnimating) {
            //for (int i = nItemsInPreview – 1; i >= 0; i–) {       
for (int i = 0; i <= nItemsInPreview – 1; i++) {
                v = (TextView) items.get(i);
                if (!mHiddenItems.contains(v.getTag())) {
                    d = v.getCompoundDrawables()[1];
                    mParams = computePreviewItemDrawingParams(i, mParams);
                    mParams.drawable = d;
                    drawPreviewItem(canvas, mParams);
                }
            }
        } else {
            drawPreviewItem(canvas, mAnimParams);
        }
                                  

~

}

    原文作者:九宫格问题
    原文地址: https://blog.csdn.net/LIAOXUNJI/article/details/43057719
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞