Skip to content
Coding Fanatic
  • Android Development
  • News and Reviews
  • Road2Pro
  • Tutorials
  • Services
  • About

Filling a Blank Canvas – 100 Days of Code…

  • May 27, 2021May 28, 2021
  • by Richard Clarke
When working with drawables, don’t forget the most basic rule of all. I tried adding an image as a background for a small project. Not only was it invisible in the Design view, testing it crashed my virtual device! Turns out I forgot one simple, obvious step. For more on this, watch the video below. You can find my source code for the app here. I tried adding an image to my HappyBirthday project. I ended up with errors about the image’s source name and the image wouldn’t render in the Design view. Additionally, I could see the outline, but it didn’t render a preview for the actual image file. I set constraints on the image to 0dp. This forced the constraint to match the parent. In this case, the image would connect with the top and bottom of the layout. The resolution didn’t match the phone so the image was forced to sit in the middle of the screen touching the left and right sides of the layout. I set the Scaletype to CenterCrop to crop the center of the androidparty image. This would use the cropped part as the full background for the layout. Once Still didn’t work I decided to delete the drawable and re-import it. When I browsed the project files, I saw the androidparty.png file wasn’t even in the same directory. It was STILL in my Downloads folder. After moving it to the project root, I re-imported the drawable and the image FINALLY rendered as expected. Last step was to create custom Strings to use for the image description and both TextViews. I stored these in the res/values/strings.xml file. It’s cool Android Studio lets you import drawables from outside the project root. However, it causes unexpected issues later down the line. Moving forward, I’ll be sure to include any and ALL project resources in the project directory first. THEN I can import drawables and anything else I need without error. For more on this, watch the video below. Join the mailing list to see updates like this every week! Coding Fanatic

Sources: Basic Android Training Course

Related

Resource Manager – 99 of 100 Days of Code
Building Apps Quickly – 1 of 100 Days of Code
Richard Clarke
Richard is currently a developer using Java and Android Studio to build custom applications for Android. Richard tutored in mathematics at Montgomery College, and worked in Information Technology before entering the Software Development industry as a Quality Engineer.
100daysofcode Android Android Development Android Studio AndroidDev development kotlin software software development

Related articles

Your New Favorite Stopwatch App!…
Two for Two BABY! 7…
…But the App is for…
Play Store Blues – 5…
Top 4 Tips for Android…
No Dice – 3 of…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • GitHub
  • YouTube
  • X
  • Instagram
  • LinkedIn
My Tweets

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • X
  • GitHub
  • LinkedIn
  • YouTube

Archives

Theme by Colorlib Powered by WordPress