【发布时间】:2014-01-11 16:55:23
【问题描述】:
我有位图图像,当我要设置为墙纸时,它是模糊的,它不适合屏幕..如何设置适当的屏幕尺寸以及如何获取屏幕尺寸以设置图像...如何解决这个问题..
class MyPagerAdapter extends PagerAdapter {
int breadset;
int forwall;
public int[] images1 = { R.drawable.s_1, R.drawable.s_2, R.drawable.s_3 };
public int[] images2 = { R.drawable.s_5, R.drawable.s_6, R.drawable.s_4 };
public MyPagerAdapter(int gotbread) {
this.breadset = gotbread;
// TODO Auto-generated constructor stub
}
public int setcall() {
return forwall;
}
public int getCount() {
return images1.length;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = null;
view = inflater.inflate(R.layout.layout_fullscreen_view, null);
((ViewPager) collection).addView(view, 0);
Button btn = (Button) view.findViewById(R.id.wallb);
ImageView iv = (ImageView) view.findViewById(R.id.imgDisplay);
switch (breadset) {
case 0:
iv.setImageResource(images1[position]);
break;
case 1:
iv.setImageResource(images2[position]);
}
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
switch (breadset) {
case 0:
myWallpaperManager.setResource(images1[forwall]);
break;
}
Context context = getApplicationContext();
CharSequence text = "wallpaper has been set to your screen!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
}
});
return view;
}
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
}
【问题讨论】:
标签: android android-imageview wallpaper image-scaling