【问题标题】:Android Shadow is not showing in ActionBarAndroid Shadow 未在 ActionBar 中显示
【发布时间】:2017-12-26 10:47:40
【问题描述】:

我对 ActionBar 的阴影有疑问,当我添加以下内容时它没有显示:android:hardwareAccelerated="false" 在我的 AndroidManifest.xml 中但是当我删除此行时,它会很好地显示阴影并在我的 Activity 中显示其他问题 @ 987654324@ 带有图像项(小尺寸图像)当我滚动Recycleview 时非常慢,但是当添加android:hardwareAccelerated="false" 时滚动是正常的。

请问有人可以帮我吗?

【问题讨论】:

  • 您的 Recycleview 究竟包含什么?并发布您的代码和活动 Xml
  • 尝试像这样设置高度的动作栏阴影 getSupportActionBar().setElevation(4) 相应地设置您的高度。
  • 设备运行的是什么版本的 Android?它是模拟器还是物理设备?

标签: android android-actionbar shadow hardware-acceleration


【解决方案1】:

根据谷歌文档

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

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

你可以做的几件事是

  1. 为您要加载重图像的特定活动添加android:hardwareAccelerated="false"Click here 进行检查。

  2. 尝试减小正在加载的图像的大小。这可以使用 android 开发者文档中记录的以下两个函数来完成。 Click here 获取完整文档。

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

另请参阅link 以获取有关图像调整大小的另一个参考。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    相关资源
    最近更新 更多