格式化字符串长度,超出部分显示省略号,区分汉字跟字母
2011-07-01 13:06
471 查看
由于android软件的显示控件上要求长度超过一定的数值就截取并加省略号,所以写了这个方法:
package com.eoeandroid.demo.testcode;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
public class bitmaptest extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setTitle("eoeAndroid教程: 缩放和旋转图片 -by:IceskYsl");
LinearLayout linLayout = new LinearLayout(this);
// 加载需要操作的图片,这里是eoeAndroid的logo图片
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.eoe_android);
//获取这个图片的宽和高
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
//定义预转换成的图片的宽度和高度
int newWidth = 200;
int newHeight = 200;
//计算缩放率,新尺寸除原始尺寸
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
//旋转图片 动作
matrix.postRotate(45);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
//将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
//创建一个ImageView
ImageView imageView = new ImageView(this);
// 设置ImageView的图片为上面转换的图片
imageView.setImageDrawable(bmd);
//将图片居中显示
imageView.setScaleType(ScaleType.CENTER);
//将ImageView添加到布局模板中
linLayout.addView(imageView,
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
)
);
// 设置为本activity的模板
setContentView(linLayout);
}
}
package com.eoeandroid.demo.testcode;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
public class bitmaptest extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setTitle("eoeAndroid教程: 缩放和旋转图片 -by:IceskYsl");
LinearLayout linLayout = new LinearLayout(this);
// 加载需要操作的图片,这里是eoeAndroid的logo图片
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.eoe_android);
//获取这个图片的宽和高
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
//定义预转换成的图片的宽度和高度
int newWidth = 200;
int newHeight = 200;
//计算缩放率,新尺寸除原始尺寸
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
//旋转图片 动作
matrix.postRotate(45);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
//将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
//创建一个ImageView
ImageView imageView = new ImageView(this);
// 设置ImageView的图片为上面转换的图片
imageView.setImageDrawable(bmd);
//将图片居中显示
imageView.setScaleType(ScaleType.CENTER);
//将ImageView添加到布局模板中
linLayout.addView(imageView,
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
)
);
// 设置为本activity的模板
setContentView(linLayout);
}
}
相关文章推荐
- 格式化字符串长度,超出部分显示省略号,区分汉字跟字母
- 格式化字符串长度,超出部分显示省略号,区分汉字跟字母
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- 截取固定长度字符串显示在页面,多余部分显示为省略号(区分汉字和字符)
- css控制标题长度超出部分显示省略号
- ASP.net:截取固定长度字符串显示在页面,多余部分显示为省略号
- css限制显示字数,文字长度超出部分用省略号表示【转】
- text-overflow:ellipsis;-moz-binding: url('ellipsis.xml#ellipsis'); 文本字符串超过容器长度溢出部分显示点点点省略号"..." ,支持IE6+,Firefox !
- css限制显示字数,文字长度超出部分用省略号表示 只显示一行
- css限制显示字数,文字长度超出部分用省略号表示
- 判断字符串的长度,汉字为2,字母数字为1,如果超出长度,跳出
- ASP.net:截取固定长度字符串显示在页面,多余部分显示为省略号
- ASP.net:截取固定长度字符串显示在页面,多余部分显示为省略号
- ASP.NET - 截取固定长度字符串显示在页面,多余部分显示为省略号
- css控制标题长度超出部分显示省略号
- css限制显示字数,文字长度超出部分用省略号表示
- js截取字符串指定长度,超出长度显示省略号
- css控制字符串不超过div的长度,超过的部分用省略号显示