Android图片相框
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
10 public static Bitmap zoomBitmap(Bitmap bitmap,int w,int h){
02
1. int width = bitmap.getWidth();
2. 03
3. int height = bitmap.getHeight();
4. 04
5. Matrix matrix = new Matrix();
6. 05
7. float scaleWidht = ((float)w / width);
8. 06
9. float scaleHeight = ((float)h / height);
10. 07
11. matrix.postScale(scaleWidht, scaleHeight);
12. 08
13. Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
14. 09
15. return newbmp;
16.
17. }
= (ImageSwitcher)findViewById(R.id.switcher01);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
g = (Gallery)findViewById(R.id.gallery01);
//如果要从sdcard取图片需要改为new ImageAdapter(this,getSD());其中getSD()为自定义的方法
g.setAdapter(new ImageAdapter(this, getSD()));
g.setOnItemSelectedListener(this);
//为单击mSwitcher设置一个监听器
//显示Switcher里的模式
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new
youtParams(LayoutParams.FILL_PARENT,LayoutParams.FILL _PARENT));
return i;
}
//将gallery中选中的图片传给ImageSwitcher
@Override
public void onItemSelected(AdapterView> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
//取的当前图片路径,并将图片的路径给了mSwitcher
path = files[position].getPath();
uri = Uri.parse("file://"+path);
//System.out.println(uri);
mSwitcher.setImageURI(uri);
itemId = position;
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private List
public ImageAdapter(){}
public ImageAdapter(Context c,List
mContext = c;
list = li;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
//显示Gallery里的模式
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView i = new ImageView(mContext);
Bitmap bm =
BitmapFactory.decodeFile(list.get(position).toString());
//System.out.println(list.get(position).toString());
i.setImageBitmap(bm);
i.setAdjustViewBounds(true);
i.setLayoutParams(new
youtParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONT ENT));
i.setBackgroundResource(R.color.black);
return i;
}
android:id="@+id/RelativeLayout01" android:layout_width="match_parent" android:layout_height="match_parent" > android:id="@+id/switcher01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" /> android:id="@+id/gallery01" android:background="#55000000" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true"