0

After scaling the image I use for my ImageButton with the Nine-patch Generator to retrieve all of the dpi files as well as maintaining the appropriate ".9" extensions, and referenced the bitmap in the src of the button, I still get the following result with the Nexus 5 virtual emulator (1080X1920, xxhdpi):

enter image description here

... There's no way in hell that the ImageButtons are 227X53 pixels (xxhdpi) here... But rather, the system retrieves a lower dpi like mdpi instead.

Here's the XML code for just one of the buttons:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/demosBtn"
    android:src="@drawable/demo_btn"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:background="@android:color/transparent" />

And as for the drawable resource file of the demo button:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/pressed_demo" android:state_pressed="true"/>
    <item android:drawable="@drawable/norm_demo"/>
</selector>

P.S. I tried this with ImageView as well, set it as clickable, set adjustViewBounds to true, and set scaleType to centerCrop, and yet it didn't work.

DaveNOTDavid
  • 1,753
  • 5
  • 19
  • 37
  • Are the images you're using real 9-patch bitmaps? If so, I could see an error like that happening. The lines above the highlighted error make me think they're not. If so, manually adding extensions will not work. What is the end effect you're trying to achieve? – wblaschko Mar 16 '16 at 18:16
  • Well, they were originally scaled png images, and then I uploaded them into the according dpi res directory, and then I "manually" changed the names of the dpi files and directory to the file's original name along with the extension ".9" if that's what you're asking lol – DaveNOTDavid Mar 16 '16 at 18:20
  • http://stackoverflow.com/questions/36039936/scaling-imagebuttons-for-various-screen-sizes... Basically, the Nexus 5 (xhdpi) emulator seems to retrieve the dpi file from the lpdi directory instead. – DaveNOTDavid Mar 16 '16 at 18:25
  • Ah, yes, a 9-patch image won't work particularly well with text on it, unless you're just stretching the edges. Honestly, you can just delete the ldpi folder, if that makes your life easier. – wblaschko Mar 16 '16 at 18:29
  • Have you tried setting the width/height of the ImageButton manually? 200dp/60dp for example? – wblaschko Mar 16 '16 at 18:31
  • Yeah, but then that'd be "hardcoding" it which would then appear humungo in QVGA – DaveNOTDavid Mar 16 '16 at 18:35
  • Question. Is there an alternative way to scaling down and uploading each image to the according dpi directories instead of using photoshop software like GIMP to resize the image and then export it from there? – DaveNOTDavid Mar 16 '16 at 18:43
  • Hardcoding dp is different than hardcoding px, it should scale pretty uniformly across devices. – wblaschko Mar 16 '16 at 18:43
  • 1
    And to answer your other question, you can look here: http://romannurik.github.io/AndroidAssetStudio/ – wblaschko Mar 16 '16 at 18:44
  • I appreciate the link as that helped me a lot! However, I still experience the same problem as shown above in my edited post... Am I supposed to be implementing this with Java code, particularly the DisplayMetrics class, as well? – DaveNOTDavid Mar 16 '16 at 19:42
  • Is this an alternative way? https://www.youtube.com/watch?v=OtsZbdbC370 – DaveNOTDavid Mar 16 '16 at 20:48

1 Answers1

1

Use SVG (Scalable vector graphics)! You can scale them to any resolution and they still look super HD. :D

  • I appreciate the suggestion, but my problem here is that whenever I reference the bitmap in the src of an ImageButton, the system selects the wrong bitmap based on the screen's dpi (as shown above in the edited post). – DaveNOTDavid Mar 16 '16 at 21:08