Kos*_*din 6 android image menu
我有图片菜单.我有大图像72x72.在活动布局中,我正在使用:
android:layout_height="55dip"
android:layout_width="55dip"
android:scaleType="fitCenter" - this works fine.
Run Code Online (Sandbox Code Playgroud)
但在菜单项中,我不知道如何做同样的事情.
Kos*_*din 10
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu,menu);
menu.findItem(R.id.menu_Help).setIcon(resizeImage(R.drawable.ic_noaction_help,108,108));
return true;
}
private Drawable resizeImage(int resId, int w, int h)
{
// load the origial Bitmap
Bitmap BitmapOrg = BitmapFactory.decodeResource(getResources(), resId);
int width = BitmapOrg.getWidth();
int height = BitmapOrg.getHeight();
int newWidth = w;
int newHeight = h;
// calculate the scale
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0,width, height, matrix, true);
return new BitmapDrawable(resizedBitmap);
}
Run Code Online (Sandbox Code Playgroud)