編輯:關於Android編程
廢話不多說了,直接給大家代碼。
具體代碼如下所示:
package com.droidhen.game.layout; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Rect; import android.widget.ImageView; public class RotateImageView extends ImageView { /**旋轉角度**/ private float _degree; /**旋轉中心**/ private float _x; private float _y; /** 背景和前景資源 */ private Bitmap _bgRes, _fgRes; /** 數字圖片資源 */ private Bitmap _nums; private Bitmap _buffer; private Canvas _canvas; private int start = ; private int unitx = ; public RotateImageView(Context context) { super(context); _degree = f; _x = ; _y = ; _nums = BitmapFactory.decodeResource(getResources(), R.drawable.level_num); } public void setResIds(int bgResId, int fgResId) { _bgRes = BitmapFactory.decodeResource(getResources(), bgResId); _fgRes = BitmapFactory.decodeResource(getResources(), fgResId); } public void setLevel(int level) { String _level = String.valueOf(level); _buffer = Bitmap.createBitmap( _level.length()*(_nums.getWidth()/), _nums.getHeight(), Config.ARGB_); unitx = _nums.getWidth()/; _canvas = new Canvas(_buffer); for(int i = ; i <= _level.length()-; i++){ Rect src = new Rect((_level.charAt(i) - '')*unitx, , (_level.charAt(i) - '' + )*unitx, _nums.getHeight()); Rect dst = new Rect( i*unitx, , (i + )*unitx, _nums.getHeight()); _canvas.drawBitmap(_nums, src, dst, null); } } public void setLevel(int level, int Resid) { _nums = BitmapFactory.decodeResource(getResources(), Resid); String _level = String.valueOf(level); _buffer = Bitmap.createBitmap( _level.length()*(_nums.getWidth()/), _nums.getHeight(), Config.ARGB_); unitx = _nums.getWidth()/; _canvas = new Canvas(_buffer); for(int i = ; i <= _level.length()-; i++){ Rect src = new Rect((_level.charAt(i) - '')*unitx, , (_level.charAt(i) - '' + )*unitx, _nums.getHeight()); Rect dst = new Rect( i*unitx, , (i + )*unitx, _nums.getHeight()); _canvas.drawBitmap(_nums, src, dst, null); } } public void setDegree(float degree) { _degree = degree; } public void setDegree(float degree, float x, float y) { _degree = degree; _x = x; _y = y; } public float getDegree() { return _degree; } public float getRotateX() { return _x; } public float getRotateY() { return _y; } @Override public void draw(Canvas canvas) { canvas.save(); canvas.setDrawFilter(new PaintFlagsDrawFilter(, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG)); canvas.rotate(_degree, _x, _y); canvas.drawBitmap(_bgRes, , , null); canvas.drawBitmap(_fgRes, , , null); canvas.drawBitmap(_buffer, (_bgRes.getWidth() - _buffer.getWidth())/f, , null); canvas.restore(); } }
以上代碼是關於Android RotateImageView 可旋轉ImageView 的全部內容,希望對大家有所幫助。
我個人感覺安卓自帶的數據庫用的不是太多的,畢竟現在很多應用都直接和服務器數據庫進行交互,或者直接API獲取一些接口的數據,但是不可否認自帶的數據庫還是有一些作用的,所以我
作為Android開發者,工作中少不了要反編譯別人的apk,當然主要目的還是為了學習到更多,取彼之長,補己之短。今天就來總結一下Android反編譯和二次打包的一些知識。
BroadcastReceiver(廣播接收器)是Android中的四大組件之一。下面就具體介紹一下Broadcast Receiver組件的用法。下面是Android
啦啦畢業了,畢業前要寫畢業設計,需要寫一個簡單的藍牙APP進行交互,通過參考網上資料,問題順利搞定,下面小編把具體實現思路分享給大家,供大家參考。1、Android藍牙編