Search code examples
javaandroidandroid-studiosvgpng

Using PNG as background image -- can't see it in design view


I have a background I created on Sketch which I want to use as the UI for the app, where I'll just put in invisible buttons where they are on the .png file.

I have the file in my drawable, and an imageview in the app with its height and width set as match_parent. Using the glide library, I loaded the image which is like 3.7MB, into the imageview, and this works, when I'm using the app on my device or emulator. The problem is, I cannot see the .png as the background when I try to put the buttons on top of the .png, since it only loads once the app starts. I've read that you could try to convert to SVG, however, when I tried this, nothing shows up.

Is there any way where I could load the image as the background another way? Or is there another way I could make a UI, or is there a way I can just load the .png?

login_activity - text

llogin_activity - design

LoginActivity Class


Solution

  • Android Studio has the nifty tools namespace.

    If you add

    tools:src="@drawable/loginscreen"
    

    to your ImageView in XML, the design view will show the image, but the attribute will be ignored during compile time and won't be present in the APK itself.

    tools: also works for most XML attributes.

    You may need to import the tools namespace (click the red tools text and hit Alt+Enter).