繁体   English   中英

Android Shadow未在ActionBar中显示

[英]Android Shadow is not showing in ActionBar

我对ActionBar的阴影有问题,当我在AndroidManifest.xml添加以下代码时,它不会显示: android:hardwareAccelerated="false" ,但是当我删除此行时,它会很好地显示阴影并在具有Recycleview Activity显示其他问题图片项目(小尺寸图片)在滚动Recycleview时非常慢,但是在添加android:hardwareAccelerated="false"滚动时是正常的。

请有人可以帮助我吗?

根据谷歌文档

从Android 3.0(API级别11)开始,Android 2D渲染管道支持硬件加速,这意味着在视图的画布上执行的所有绘图操作都使用GPU。 由于启用硬件加速所需的资源增加,因此您的应用程序将消耗更多的RAM。

所以我猜写android:hardwareAccelerated="false"阻止应用程序使用GPU,从而减少了GPU渲染的效果,例如阴影。

您可以做的几件事是

  1. 为要加载沉重图像的特定活动添加android:hardwareAccelerated="false" 单击此处进行检查。

  2. 尝试减小要加载的图像的大小。 可以使用android开发人员文档中记录的以下两个功能来完成此操作。 单击此处以获取完整的文档。

功能1

public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

    final int halfHeight = height / 2;
    final int halfWidth = width / 2;

    // Calculate the largest inSampleSize value that is a power of 2 and keeps both
    // height and width larger than the requested height and width.
    while ((halfHeight / inSampleSize) >= reqHeight
            && (halfWidth / inSampleSize) >= reqWidth) {
        inSampleSize *= 2;
    }
}

return inSampleSize;
}

功能2

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
    int reqWidth, int reqHeight) {

// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);

// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}

在ImageView中设置图像

mImageView.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));

另请参阅此链接以获取有关图像调整大小的另一参考。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM