[英]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渲染的效果,例如陰影。
您可以做的幾件事是
為要加載沉重圖像的特定活動添加android:hardwareAccelerated="false"
。 單擊此處進行檢查。
嘗試減小要加載的圖像的大小。 可以使用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.