简体   繁体   English

Android Shadow未在ActionBar中显示

[英]Android Shadow is not showing in ActionBar

I have problem with shadow of ActionBar it doesn't show when i add this : android:hardwareAccelerated="false" in my AndroidManifest.xml but when i delete this line it show shadow well and show other problem in my Activity which has Recycleview with items of images(small size images) it be very slow when i scroll the Recycleview , but when add android:hardwareAccelerated="false" scrolling be normal. 我对ActionBar的阴影有问题,当我在AndroidManifest.xml添加以下代码时,它不会显示: android:hardwareAccelerated="false" ,但是当我删除此行时,它会很好地显示阴影并在具有Recycleview Activity显示其他问题图片项目(小尺寸图片)在滚动Recycleview时非常慢,但是在添加android:hardwareAccelerated="false"滚动时是正常的。

Please anyone could help me with this? 请有人可以帮助我吗?

According to google documentation 根据谷歌文档

Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline supports hardware acceleration, meaning that all drawing operations that are performed on a View's canvas use the GPU. 从Android 3.0(API级别11)开始,Android 2D渲染管道支持硬件加速,这意味着在视图的画布上执行的所有绘图操作都使用GPU。 Because of the increased resources required to enable hardware acceleration, your app will consume more RAM. 由于启用硬件加速所需的资源增加,因此您的应用程序将消耗更多的RAM。

So i guess writing android:hardwareAccelerated="false" stops the app from making use of the GPU, hence reducing GPU rendered effects like shadows. 所以我猜写android:hardwareAccelerated="false"阻止应用程序使用GPU,从而减少了GPU渲染的效果,例如阴影。

A couple of things that you can do is 您可以做的几件事是

  1. Add the android:hardwareAccelerated="false" for the specific activity where you want to load heavy images. 为要加载沉重图像的特定活动添加android:hardwareAccelerated="false" Click here to check that. 单击此处进行检查。

  2. Try and reduce the size of the images that you are loading. 尝试减小要加载的图像的大小。 This can be done using the following two functions as documented in the developer documentation for android. 可以使用android开发人员文档中记录的以下两个功能来完成此操作。 Click here for the complete documentation. 单击此处以获取完整的文档。

Function 1 功能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;
}

Function 2 功能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);
}

Set Image in ImageView 在ImageView中设置图像

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

Also refer this link for a another reference about Image Resizing. 另请参阅此链接以获取有关图像调整大小的另一参考。

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

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