安卓快捷键位启动图标大小 [英] Android shortcut bitmap launcher icon size

查看:368
本文介绍了安卓快捷键位启动图标大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,找出正确的启动图标大小为我的快捷方式。

在我的Nexus 7.2 android.R.dimen.app_icon_size的价值(见code)为96像素。 但是,如果我衡量我的主屏幕的截图其他应用程序的实际图标大小,它是120个像素。创建shortshut后,它更小(96像素),比其他所有的应用程序图标(120px)

在我的三星Galaxy SII android.R.dimen.app_icon_size为72。而这场比赛给我的截图措施。

下面的结果

  DisplayMetrics指标=新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(度量)。
 

的Nexus 7.2:

  android.R.dimen.app_icon_size = 96
metrics.dip = 192
metrics.density = 2.0
metrics.densityDpi = 320
metrics.heightPixels = 1824
metrics.scaledDensity = 2.0
metrics.widthPixels = 1200
metrics.xdpi = 320.842
metrics.ydpi = 322.966
 

三星SII:

  android.R.dimen.app_icon_size = 72
metrics.dip = 108
metrics.density = 1.5
metrics.densityDpi = 240
metrics.heightPixels = 800
metrics.scaledDensity = 1.5
metrics.widthPixels = 480
metrics.xdpi = 217.71428
metrics.ydpi = 218.49463
 

下面我code:

  //计算启动图标大小
INT大小=(int)的getResources()getDimension(android.R.dimen.app_icon_size)。
INT宽度=大小;
INT高=大小;

//创建启动器图标位图
点阵位图= Bitmap.createBitmap(宽度,高度,Bitmap.Config.ARGB_8888);
帆布油画=新的Canvas(位);

//充气布局位图
LayoutInflater充气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
的LinearLayout布局=(的LinearLayout)inflater.inflate(R.layout.shortcut,空,假);
//这里我编辑的布局,变化的ImageView和TextView的等..
layout.setDrawingCacheEnabled(真正的);
layout.measure(MeasureSpec.makeMeasureSpec(宽度,MeasureSpec.EXACTLY),MeasureSpec.makeMeasureSpec(高度,MeasureSpec.EXACTLY));
layout.layout(0,0,layout.getMeasuredWidth(),layout.getMeasuredHeight());
canvas.drawBitmap(layout.getDrawingCache(),0,0,新涂料());

//创建sendfax的意图
意图shortcutIntent =新意图();
shortcutIntent.setClass(背景下,SendFax.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

//创建快捷方式的意图
意向意图=新的意图();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,位图);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,说明);

的setResult(RESULT_OK,意图);
完();
 

解决方案

我已经找到了一个有效的解决方案:

  @TargetApi(Build.VERSION_ codeS.HONEYCOMB)
私人诠释launcherLargeIconSize(){
    ActivityManager activityManager =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    返回activityManager.getLauncherLargeIconSize();
}

INT尺寸1 =(int)的getResources()getDimension(android.R.dimen.app_icon_size)。
INT size2个= Build.VERSION.SDK_INT> = 11? launcherLargeIconSize():0;
INT大小= size2个>尺寸1? size2个:尺寸1;
 

I have problems to find out the correct launcher icon size for my shortcut.

On my Nexus 7.2 the value of android.R.dimen.app_icon_size (see code) is 96 pixels. But if I measure the real icon size of other apps on a screenshot of my homescreen, it is 120 pixels. After creating a shortshut, it is smaller (96 px) than all other app icons (120px)

On my Samsung Galaxy SII android.R.dimen.app_icon_size is 72. And this match to my screenshot measure.

Here the result of

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

Nexus 7.2:

android.R.dimen.app_icon_size = 96
metrics.dip = 192
metrics.density = 2.0
metrics.densityDpi = 320
metrics.heightPixels = 1824
metrics.scaledDensity = 2.0
metrics.widthPixels = 1200
metrics.xdpi = 320.842
metrics.ydpi = 322.966

Samsung SII:

android.R.dimen.app_icon_size = 72
metrics.dip = 108
metrics.density = 1.5
metrics.densityDpi = 240
metrics.heightPixels = 800
metrics.scaledDensity = 1.5
metrics.widthPixels = 480
metrics.xdpi = 217.71428
metrics.ydpi = 218.49463

Here my code:

// Calculate launcher icon size
int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
int width = size;
int height = size;

// Create launcher icon bitmap      
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

// Inflate layout to bitmap
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.shortcut, null, false);
// here I edit layout, change ImageView and TextView etc...
layout.setDrawingCacheEnabled(true);
layout.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());
canvas.drawBitmap(layout.getDrawingCache(), 0, 0, new Paint());

// Create SendFax intent
Intent shortcutIntent = new Intent();
shortcutIntent.setClass(context, SendFax.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

// Create shortcut intent               
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description);

setResult(RESULT_OK, intent);
finish();

解决方案

I have found out a working solution:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private int launcherLargeIconSize() {
    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    return activityManager.getLauncherLargeIconSize();
}

int size1 = (int) getResources().getDimension(android.R.dimen.app_icon_size);
int size2 = Build.VERSION.SDK_INT >= 11 ? launcherLargeIconSize() : 0;
int size = size2 > size1 ? size2 : size1;

这篇关于安卓快捷键位启动图标大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆