0

In my application I set android:hardwareAccelerated="true". I have one layout that have large image (1600 x 2500). When I run my application the background was gone all I have black background. So when I set

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

the background image shows again. When I set background as a color it works fine.

So what is the problem here or what I did wrong. I want show image when android:hardwareAccelerated is turned on.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/firstbg"
    android:clickable="true">
</LinearLayout>
fish40
  • 5,738
  • 17
  • 50
  • 69

1 Answers1

1

Using android:hardwareAccelerated makes Android to upload your images to CPU memory. There is a limitation there on the size of the image and it also depends on the openGL version. I don't remember what are the max dimensions but your image is probably to large. It works with colors as a different algorithm used to render colors.

I am sure if you will try using a smaller image it will work for you.

Edit: If you must use large image, your only option is cutting it to smaller peaces and use it as some sort of puzzle, but it will effect your performance. Try to find a way to reduce it's size.

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
  • Thank you @Babibu it works when I put smaller images. but is there any alternative solution. I have to use large images and there is no other way – fish40 Dec 22 '13 at 12:43
  • I think limitation is 2048x2048 – MalaKa Dec 22 '13 at 12:49
  • @MalaKa can you give us a reference? – Ilya Gazman Dec 22 '13 at 12:50
  • I just tried to google, but I can't find it right now. I got the value in the logcat when I had the same issue. – MalaKa Dec 22 '13 at 12:56
  • I just found something in `Canvas`. See [here](http://developer.android.com/reference/android/graphics/Canvas.html#getMaximumBitmapHeight%28%29). I'm not sure if this is part of the issue, but the existance of the method makes me think that there is no limitation by android, but by the device itself. – MalaKa Dec 22 '13 at 13:06
  • @MalaKa this is not related. – Ilya Gazman Dec 22 '13 at 13:07