问题
I want my app to use a image in the background for signup and signin function. I am using android studio 2.3 and so far I can see that lot many things have changed since last year. Where we used relative or linearlayout now that is constraint layout. I included a code with the root layout as:
android:background="@drawable/wallpaper_2"
android:orientation="vertical"
Check this image for more information:
When I test this app on my Nexus 5 it does not show anything just a blank screen but the it shows the same image on the preview screen. Any help would be appreciated on this.
回答1:
The resolution of your image is too large for the device resize your picture to smaller dimesions and based on that put your image into specific drawable folder. e.g : If image size is 1280 x 720
than put image in drawable-xxhdpi folder.
回答2:
To prevent Bitmap too large error, you can simply use libraries like Glide or Picasso. These libraries take care of all memory handling
回答3:
Multiple option to work around
1- Change
android:background="@drawable/wallpaper_2"
To
android:background="@drawable/wallpaper"
numbers are not allowed in drawable names.
2- check image size if its too large replace it with a smaller sized image.
3- You can add android:largheap="true"
in application tag in case image is large in resolution
4- Add a relative layout inside constraint layout or replace constraint layout with relative layout and then apply background
回答4:
firstly create all drawable file version for each dpi size
drawable-mdpi drawable-hdpi drawable-xhdpi drawable-xxhdpi drawable-xxxhdpi
then put your image by right click on res file and then chose image assert. after this step it will work i think
回答5:
On Ubuntu 16.04 paste the image into the workspace -> project name-> app-> src-> main -> res -> drawable. This worked for me instead only pasting directly into Android Studio 3.1.3 app -> res -> drawable
来源:https://stackoverflow.com/questions/43446661/background-image-in-constraints-layout-does-not-work