欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

采用Bitmap的extractAlpha產(chǎn)生圖片邊緣光暈效果

系統(tǒng) 1755 0
????? 前幾天使用一款android手機測試的時候,
發(fā)現(xiàn)了應用的 shortcut 九宮格頁面有一個點擊效果,
就是當點擊一個應用的icon圖標的時候,會在icon的周圍有熒光效果,
無論icon的形狀是什么樣子的都會有這樣的效果,然后又想到Apidemo里面有個alphaDrawable例子
大家可以去在回顧一下,之后我就想到了會不會是使用這個extractAlpha實現(xiàn)的,自己就動手寫了個例子
發(fā)現(xiàn)效果確實不錯,分享給大家
主要關鍵點
1、設置imageview的src drawable
2、從src drawable中抽取 bitmap的alpha(只有透明度沒有顏色)
3、使用bitmap的alpha填充一種顏色后生產(chǎn)新的bitmap
4、使用新生成的bitmap做一個statelistdrawable作為imageview的backgroud
5、這需要注意的是要跟imageview設置幾個像素的padding這樣才不會讓src和backgroud重合

采用Bitmap的extractAlpha產(chǎn)生圖片邊緣光暈效果

采用Bitmap的extractAlpha產(chǎn)生圖片邊緣光暈效果

采用Bitmap的extractAlpha產(chǎn)生圖片邊緣光暈效果
主要的代碼:
    
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.study;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * A layout that arranges its children in a grid.  The size of the
 * cells is set by the {@link #setCellSize} method and the
 * android:cell_width and android:cell_height attributes in XML.
 * The number of rows and columns is determined at runtime.  Each
 * cell contains exactly one view, and they flow in the natural
 * child order (the order in which they were added, or the index
 * in {@link #addViewAt}.  Views can not span multiple cells.
 */
public class FixedGridLayout extends ViewGroup {
    int mCellWidth;
    int mCellHeight;

    public FixedGridLayout(Context context) {
        super(context);
    }

    public FixedGridLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        // Read the resource attributes.
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedGridLayout);
        mCellWidth = a.getDimensionPixelSize(R.styleable.FixedGridLayout_cellWidth, -1);
        mCellHeight = a.getDimensionPixelSize(R.styleable.FixedGridLayout_cellHeight, -1);
        a.recycle();
        
    }

    public void setCellWidth(int px) {
        mCellWidth = px;
        requestLayout();
    }

    public void setCellHeight(int px) {
        mCellHeight = px;
        requestLayout();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int cellWidthSpec = MeasureSpec.makeMeasureSpec(mCellWidth, MeasureSpec.AT_MOST);
        int cellHeightSpec = MeasureSpec.makeMeasureSpec(mCellHeight, MeasureSpec.AT_MOST);

        int count = getChildCount();
        for (int index=0; index<count; index++) {
            final View child = getChildAt(index);
            child.measure(cellWidthSpec, cellHeightSpec);
        }
        // Use the size our parents gave us
        setMeasuredDimension(resolveSize(mCellWidth*count, widthMeasureSpec),
                resolveSize(mCellHeight*count, heightMeasureSpec));
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int cellWidth = mCellWidth;
        int cellHeight = mCellHeight;
        int columns = (r - l) / cellWidth;
        if (columns < 0) {
            columns = 1;
        }
        int x = 0;
        int y = 0;
        int i = 0;
        int count = getChildCount();
        for (int index=0; index<count; index++) {
            final View child = getChildAt(index);

            int w = child.getMeasuredWidth();
            int h = child.getMeasuredHeight();

            int left = x + ((cellWidth-w)/2);
            int top = y + ((cellHeight-h)/2);

            child.layout(left, top, left+w, top+h);
            if (i >= (columns-1)) {
                // advance to next row
                i = 0;
                x = 0;
                y += cellHeight;
            } else {
                i++;
                x += cellWidth;
            }
        }
    }
    
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        int cnt = getChildCount();
        Paint p = new Paint();
        p.setColor(Color.CYAN);
        
        for (int i=0; i<cnt; i++) {
            View v = getChildAt(i);
            setStateDrawable((ImageView)v, p);
        }
    }
	
	private void setStateDrawable(ImageView v, Paint p) {
		BitmapDrawable bd = (BitmapDrawable) v.getDrawable();
		Bitmap b = bd.getBitmap();
		Bitmap bitmap = Bitmap.createBitmap(bd.getIntrinsicWidth(), bd.getIntrinsicHeight(), Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		canvas.drawBitmap(b.extractAlpha(), 0, 0, p);
		
		StateListDrawable sld = new StateListDrawable();
		sld.addState(new int[]{android.R.attr.state_pressed}, new BitmapDrawable(bitmap));
		
		v.setBackgroundDrawable(sld);
	}
}

  


具體見附件。

為ImageView或者LinearLayout畫圖片陰影
http://407827531.iteye.com/blog/1194984

圖片陰影效果和影子效果
http://www.eoeandroid.com/thread-90575-1-2.html

采用Bitmap的extractAlpha產(chǎn)生圖片邊緣光暈效果


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产精品免费av | www.91在线 | 久久好在线视频 | 香港午夜三级a三级高清观看 | 欧美午夜在线 | 人人爱天天做夜夜爽 | 亚洲天堂欧美在线 | 偷拍亚洲制服另类无码专区 | 久久综合一个色综合网 | 久草福利资源网站免费 | 欧美日韩亚洲一区 | 午夜精品影院 | 天天在线欧美精品免费看 | 国产成人理在线观看视频 | 日韩天天干 | 明明电影高清在线观看 | 日韩午夜影院 | 亚洲 欧美 日韩 在线 香蕉 | 欧洲成人全免费视频网站 | 国产精品国产 | 五月天婷婷网站 | 日韩专区在线观看 | 日韩一级一欧美一级国产 | 一级片国产片 | 国产欧美久久一区二区三区 | 免费人成年短视频在线观看免费网站 | 天天操天天插 | 国产中文视频 | 九色在线观看 | 狠狠做深爱婷婷久久一区 | 日本免费不卡在线一区二区三区 | 国产综合亚洲精品一区二 | 香蕉视频免费网站 | 天天天天天天天操 | 69久久夜色精品国产69 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲欧美在线视频免费 | 欧美交性又色又爽又黄 | 欧美精品38videos性欧美 | 亚洲一区二区三区在线播放 | 免费欧美黄色网址 |