Android動態設置android:drawableLeft|Right|Top|Bottom 並根據分辨率自適應


http://blog.sina.com.cn/s/blog_4b93170a0102e1m9.html

//調用setCompoundDrawables時,必須調用Drawable.setBounds()方法,否則圖片不顯示 最主要一點,不然不顯示圖片,搞了半天

/**
         * 從png文件得到Bitmap
         * 並且將尺寸調整為寬=w、高=h
         */
        public static Bitmap getMyBitmap(String imageName, int w, int h){
                String filePath = IMAGE_PATH + "/" + imageName + ".png";
                Bitmap oldbmp = BitmapFactory.decodeFile(filePath);
                if(oldbmp!=null){
                        int width = oldbmp.getWidth();
                        int height = oldbmp.getHeight();
                        Matrix matrix = new Matrix();
                        float scaleWidth = ((float) w / width);
                        float scaleHeight = ((float) h / height);
                        matrix.postScale(scaleWidth, scaleHeight);
                        Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true);
                        return newbmp;
                }
                else{
                        return null;
                }
        }

調整分辨率

 

http://blog.sina.com.cn/s/blog_4607d856010125sl.html BitmapDrawable的使用轉換


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM