当前位置: 代码迷 >> Android >> android一些技艺
  详细解决方案

android一些技艺

热度:54   发布时间:2016-05-01 15:27:53.0
android一些技巧
                EditText ed = new EditText(this);        Editable eb = ed.getEditableText();        //获取光标位置        int position = ed.getSelectionStart();        //指定位置插入字符        eb.insert(position, "XXX");        //插入图片        //定义图片所占字节数(“Tag”的长度)        SpannableString ss = new SpannableString("Tag");        //定义插入图片        Drawable drawable = getResources().getDrawable(R.drawable.icon);        ss.setSpan(new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE), 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        drawable.setBounds(2, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());        //插入图片        eb.insert(position, ss);        //设置可输入最大字节数        ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});        //拉起lancher桌面        Intent i = new Intent(Inten.ACTION_MAIN);       i.addCategory(Inten.CATEGORT_HOME);       startActivity(i);       //去掉List拖动时的阴影        list.setCacheColorHint(0);                   // 通过资源名称获取资源id         1.Field f= (Field)R.drawable.class.getDeclaredField("Name");        int id=f.getInt(R.drawable.class);     2.int id = getResources().getIdentifier(getPackageName()+":drawable/Name", null,null);       // timer TimerTask用法        mTimer = new Timer();        mTimerTask = new TimerTask() {			@Override			public void run() {				mProgress.setProgress(mMediaPlayer.getCurrentPosition());				mHandler.sendEmptyMessage(0);			}		};		mTimer.schedule(mTimerTask, 0, 1000);        // 在a.apk启动b.apk的实现         //1.a.apk实现	Intent mIntent = new Intent("package.MainActivity"); 	startActivity(mIntent);	finish();         // b.apk在mainfest中配置            <intent-filter>                <action android:name="package.MainActivity" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>//Android 获取存储卡路径和空间使用情况       /** 获取存储卡路径 */ File sdcardDir=Environment.getExternalStorageDirectory(); /** StatFs 看文件系统空间使用情况 */ StatFs statFs=new StatFs(sdcardDir.getPath()); /** Block 的 size*/ Long blockSize=statFs.getBlockSize(); /** 总 Block 数量 */ Long totalBlocks=statFs.getBlockCount(); /** 已使用的 Block 数量 */ Long availableBlocks=statFs.getAvailableBlocks(); //Android 为Activity屏幕的标题添加图标Window win = getWindow();  win.requestFeature(Window.FEATURE_LEFT_ICON);  setContentView(R.layout.mylayout);  win.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);//图片缩放1.ThumbnailUtils.extractThumbnail(bitmap,200,100)2.  //使用Bitmap加Matrix来缩放        public static Drawable resizeImage(Bitmap bitmap, int w, int h)        {            Bitmap BitmapOrg = bitmap;             int width = BitmapOrg.getWidth();             int height = BitmapOrg.getHeight();             int newWidth = w;             int newHeight = h;                float scaleWidth = ((float) newWidth) / width;             float scaleHeight = ((float) newHeight) / height;                Matrix matrix = new Matrix();             matrix.postScale(scaleWidth, scaleHeight);             // if you want to rotate the Bitmap               // matrix.postRotate(45);               Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,                             height, matrix, true);             return new BitmapDrawable(resizedBitmap);         }  3. //使用BitmapFactory.Options的inSampleSize参数来缩放        public static Drawable resizeImage2(String path,               int width,int height)        {           BitmapFactory.Options options = new BitmapFactory.Options();           options.inJustDecodeBounds = true;//不加载bitmap到内存中            BitmapFactory.decodeFile(path,options);            int outWidth = options.outWidth;           int outHeight = options.outHeight;           options.inDither = false;           options.inPreferredConfig = Bitmap.Config.ARGB_8888;           options.inSampleSize = 1;                      if (outWidth != 0 && outHeight != 0 && width != 0 && height != 0)            {               int sampleSize=(outWidth/width+outHeight/height)/2;               Log.d(tag, "sampleSize = " + sampleSize);               options.inSampleSize = sampleSize;           }                 options.inJustDecodeBounds = false;           return new BitmapDrawable(BitmapFactory.decodeFile(path, options));            }  

?

  相关解决方案