本篇文章為大家展示了Android開發中怎么實現一個iOS中的毛玻璃效果,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
成都創新互聯專注于漢陰網站建設服務及定制,我們擁有豐富的企業做網站經驗。 熱誠為您提供漢陰營銷型網站建設,漢陰網站制作、漢陰網頁設計、漢陰網站官網定制、小程序開發服務,打造漢陰網絡公司原創品牌,更為您提供漢陰網站排名全網營銷落地服務。
實現代碼:
<html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"></head><body><textarea >private void applyBlur() { image.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { image.getViewTreeObserver().removeOnPreDrawListener(this); image.buildDrawingCache(); Bitmap bmp = image.getDrawingCache(); blur(bmp, text, true); return true; } }); } @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void blur(Bitmap bkg, View view) { long startMs = System.currentTimeMillis(); float radius = 20; Bitmap overlay = Bitmap.createBitmap((int)(view.getMeasuredWidth()), (int)(view.getMeasuredHeight()), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft(), -view.getTop()); canvas.drawBitmap(bkg, 0, 0, null); RenderScript rs = RenderScript.create(SecondActivity.this); Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement()); blur.setInput(overlayAlloc); blur.setRadius(radius); blur.forEach(overlayAlloc); overlayAlloc.copyTo(overlay); view.setBackground(new BitmapDrawable(getResources(), overlay)); rs.destroy(); statusText.setText("cost " + (System.currentTimeMillis() - startMs) + "ms"); }</textarea></body></html>
布局如下:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/picture" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/splash" android:scaleType="centerCrop" /> <TextView android:id="@+id/text" android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Gaussian Blur" android:textColor="@android:color/black" android:layout_gravity="center_vertical" android:textStyle="bold" android:textSize="48sp" /> <LinearLayout android:id="@+id/controls" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#7f000000" android:orientation="vertical" android:layout_gravity="bottom" /> </FrameLayout>
上述內容就是Android開發中怎么實現一個iOS中的毛玻璃效果,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創新互聯行業資訊頻道。
文章名稱:Android開發中怎么實現一個iOS中的毛玻璃效果
標題來源:http://m.newbst.com/article40/jeshho.html
成都網站建設公司_創新互聯,為您提供服務器托管、網站策劃、面包屑導航、商城網站、移動網站建設、網站設計
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯