格式化字符串长度,超出部分显示省略号,区分汉字跟字母

来源:互联网 发布:gta5渣电脑神优化20桢 编辑:程序博客网 时间:2024/05/16 18:14


  1. package com.eoeandroid.demo.testcode;  
  2. import android.app.Activity;  
  3. import android.graphics.Bitmap;  
  4. import android.graphics.BitmapFactory;  
  5. import android.graphics.Matrix;  
  6. import android.graphics.drawable.BitmapDrawable;  
  7. import android.os.Bundle;  
  8. import android.view.ViewGroup.LayoutParams;  
  9. import android.widget.ImageView;  
  10. import android.widget.LinearLayout;  
  11. import android.widget.ImageView.ScaleType;  
  12. public class bitmaptest extends Activity {  
  13. public void onCreate(Bundle icicle) {  
  14.         super.onCreate(icicle);  
  15.         setTitle("eoeAndroid教程: 缩放和旋转图片 -by:IceskYsl");  
  16.         LinearLayout linLayout = new LinearLayout(this);  
  17.         // 加载需要操作的图片,这里是eoeAndroid的logo图片  
  18.         Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),  
  19.                R.drawable.eoe_android);  
  20.         //获取这个图片的宽和高  
  21.         int width = bitmapOrg.getWidth();  
  22.         int height = bitmapOrg.getHeight();  
  23.         //定义预转换成的图片的宽度和高度  
  24.         int newWidth = 200;  
  25.         int newHeight = 200;  
  26.         //计算缩放率,新尺寸除原始尺寸  
  27.         float scaleWidth = ((float) newWidth) / width;  
  28.         float scaleHeight = ((float) newHeight) / height;  
  29.         // 创建操作图片用的matrix对象  
  30.         Matrix matrix = new Matrix();  
  31.         // 缩放图片动作  
  32.         matrix.postScale(scaleWidth, scaleHeight);  
  33.         //旋转图片 动作  
  34.         matrix.postRotate(45);  
  35.         // 创建新的图片  
  36.         Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 00,  
  37.                           width, height, matrix, true);  
  38.         //将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中  
  39.         BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);  
  40.         //创建一个ImageView  
  41.         ImageView imageView = new ImageView(this);  
  42.         // 设置ImageView的图片为上面转换的图片  
  43.         imageView.setImageDrawable(bmd);  
  44.         //将图片居中显示  
  45.         imageView.setScaleType(ScaleType.CENTER);  
  46.         //将ImageView添加到布局模板中  
  47.         linLayout.addView(imageView,  
  48.           new LinearLayout.LayoutParams(  
  49.                       LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT  
  50.                 )  
  51.         );  
  52.         // 设置为本activity的模板  
  53.         setContentView(linLayout);  
  54.     }  
  55. }  
  1. package com.eoeandroid.demo.testcode;  
  2. import android.app.Activity;  
  3. import android.graphics.Bitmap;  
  4. import android.graphics.BitmapFactory;  
  5. import android.graphics.Matrix;  
  6. import android.graphics.drawable.BitmapDrawable;  
  7. import android.os.Bundle;  
  8. import android.view.ViewGroup.LayoutParams;  
  9. import android.widget.ImageView;  
  10. import android.widget.LinearLayout;  
  11. import android.widget.ImageView.ScaleType;  
  12. public class bitmaptest extends Activity {  
  13. public void onCreate(Bundle icicle) {  
  14.         super.onCreate(icicle);  
  15.         setTitle("eoeAndroid教程: 缩放和旋转图片 -by:IceskYsl");  
  16.         LinearLayout linLayout = new LinearLayout(this);  
  17.         // 加载需要操作的图片,这里是eoeAndroid的logo图片  
  18.         Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),  
  19.                R.drawable.eoe_android);  
  20.         //获取这个图片的宽和高  
  21.         int width = bitmapOrg.getWidth();  
  22.         int height = bitmapOrg.getHeight();  
  23.         //定义预转换成的图片的宽度和高度  
  24.         int newWidth = 200;  
  25.         int newHeight = 200;  
  26.         //计算缩放率,新尺寸除原始尺寸  
  27.         float scaleWidth = ((float) newWidth) / width;  
  28.         float scaleHeight = ((float) newHeight) / height;  
  29.         // 创建操作图片用的matrix对象  
  30.         Matrix matrix = new Matrix();  
  31.         // 缩放图片动作  
  32.         matrix.postScale(scaleWidth, scaleHeight);  
  33.         //旋转图片 动作  
  34.         matrix.postRotate(45);  
  35.         // 创建新的图片  
  36.         Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 00,  
  37.                           width, height, matrix, true);  
  38.         //将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中  
  39.         BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);  
  40.         //创建一个ImageView  
  41.         ImageView imageView = new ImageView(this);  
  42.         // 设置ImageView的图片为上面转换的图片  
  43.         imageView.setImageDrawable(bmd);  
  44.         //将图片居中显示  
  45.         imageView.setScaleType(ScaleType.CENTER);  
  46.         //将ImageView添加到布局模板中  
  47.         linLayout.addView(imageView,  
  48.           new LinearLayout.LayoutParams(  
  49.                       LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT  
  50.                 )  
  51.         );  
  52.         // 设置为本activity的模板  
  53.         setContentView(linLayout);  
  54.     }  
  55. }  
0 0
原创粉丝点击