当前位置: 编程技术>移动开发
本页文章导读:
▪一个函数,很好解决图片过大导致内存溢出有关问题 一个函数,很好解决图片过大导致内存溢出问题
最近在做个项目,由于用到图片较多,而且图片的像素都很高,所以老是有内存溢出的问题(尤其是在电脑的虚拟机下),然后就用到了一个.........
▪ ListView的右侧滚动滑块 ListView的右边滚动滑块
ListView的右边滚动滑块:
XML布局只需要在ListView节点加入:
android:fastScrollEnabled="true"
代码中:
listView.setFastScrollEnabled(true);
设置监听:
listView.setOnScrollListener(new On.........
▪ byte String 变换 byte String 转换
public class ChangeVar {
public static void main(String[] args) {
String str = "123456789abcdefg";
byte[] b = str.getBytes();
//wrong
String str_a = b.toString();
System.out.println(str_a);
//right
String str.........
[1]一个函数,很好解决图片过大导致内存溢出有关问题
来源: 互联网 发布时间: 2014-02-18
一个函数,很好解决图片过大导致内存溢出问题
最近在做个项目,由于用到图片较多,而且图片的像素都很高,所以老是有内存溢出的问题(尤其是在电脑的虚拟机下),然后就用到了一个处理图片的函数,很有用,帮我解决了这个问题,在这里跟大家分享。
public Bitmap getLoacalBitmap(String path) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// path是图片所在位置
BitmapFactory.decodeFile(path, options); //这里不加载图片,只是取图片大小
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
options.inSampleSize = 1;
options.inPreferredConfig = Bitmap.Config.RGB_565; //这里用2字节显示图片,一般是4字节(默认
//判断如果使用内存大于3M,你可以修改这个参数,一般10M应该OK
int ratio = imageWidth * imageHeight * 2 / 3000000;
options.inSampleSize = 1; //不缩放,保持原来的大小
if (ratio >= 1) {
options.inSampleSize = 2; //宽度和高度将缩小两倍,width/2 and height/2,所以图片会模糊,不过不会消耗很多内存
}
if (ratio >= 4) {
options.inSampleSize = 3;
}
// options.inSampleSize = 1;
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(path, options); //真正的加载图片
return bitmap;
}
[2] ListView的右侧滚动滑块
来源: 互联网 发布时间: 2014-02-18
ListView的右边滚动滑块
ListView的右边滚动滑块:
XML布局只需要在ListView节点加入:
android:fastScrollEnabled="true"
代码中:
listView.setFastScrollEnabled(true);
设置监听:
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
Log.d("test", "onScrollStateChanged");
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
Log.d("test", "onScroll");
}
});
自定义右边的滚动滑块:
转载:http://blog.csdn.net/pointerfree/article/details/6779196
private void slipPic() {
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(listView); //listview 控件
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.icon);
f.set(o, drawable);
Toast.makeText(this, f.getType().getName(), 1000).show();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
[3] byte String 变换
来源: 互联网 发布时间: 2014-02-18
byte String 转换
public class ChangeVar {
public static void main(String[] args) {
String str = "123456789abcdefg";
byte[] b = str.getBytes();
//wrong
String str_a = b.toString();
System.out.println(str_a);
//right
String str_b = new String(b);
System.out.println(str_b);
}
}
最新技术文章: