-3

I'm developing an android app and I have a custom layout that I need to support for all the screen sizes. for that I created images and placed them in different dpi folders (mdpi to xxhdpi)!. But Android Studio uses only the resources from one dpi folder for all screen sizes on actual device as well as emulators.

Please tell me what to do? app launch is to be done in few days.

how it looks on Moto G2

how it looks on Nexus 7

thanks in advance!

equitharn
  • 3,453
  • 2
  • 14
  • 17
  • What is the exact folder structure you are using for these resources? How do you *know* that Android is using only resources from one folder? – Bryan Herbst May 21 '15 at 13:56
  • How do you know that "Android Studio uses only the resources from one dpi folder for all screen sizes on actual device as well as emulators" ? What made you come to that conclusion? Do share. – Bidhan May 21 '15 at 13:56
  • I hope the images that you have placed in the different folders are also differently scaled.... The framework wont scale them for you. – Quark May 21 '15 at 13:58
  • @Bidhan A before creating different images, I used only one set of images and then the layout on tab was same. it's same even after creating images for different DPI. Moreover the height and width are set to wrap_content – equitharn May 21 '15 at 14:16
  • @Tanis.7x I don't exactly know if they are being used from the same folder or not. but I have scaled images accordingly. – equitharn May 21 '15 at 14:18
  • @Quark yes they are scaled properly. – equitharn May 21 '15 at 14:19
  • What are the dimensions of the assets you showed in your screenshots, and what does your drawable folder structure look like? – Bryan Herbst May 21 '15 at 14:20
  • I think the problem is not the drawables scaling but a layaout design problem. Do not set your buttons to `wrap_content`and fix the size in dpis. Use the drawables as background. – Quark May 21 '15 at 14:22
  • @Tanis.7x mdpi is 100x100 hdpi is 150x150 xhdpi is 200x200 xxhdpi is 300x300 not my screenshot but it's how my structure looks like: http://4.bp.blogspot.com/-QVosaN6xSHU/VI9epwg9w3I/AAAAAAAAAr4/dcG1PeJPgIs/s1600/structure.png – equitharn May 21 '15 at 14:29
  • @Quark drawables are used as background only. and as for the first line I didn't get it. – equitharn May 21 '15 at 14:33
  • I dont exactly understand what your are traying to accomplish. But try to remove all drawables but the xhdpi, that way you make sure that any display will use that drawable and check what happens. – Quark May 21 '15 at 14:35
  • @Quark result is the same as shown in the screenshots. – equitharn May 21 '15 at 14:40
  • @Quark what I'm trying to do is create a uniform look across all devices. – equitharn May 21 '15 at 14:53

2 Answers2

1

@Quark what I'm trying to do is create a uniform look across all devices.

What I think is that you are trying to use drawables to occupy the same size across different secreen dpi and size, but you are doing it wrong. If you think using different sezed drawables will make the buttons adapt to any different screen you are mistaken, because you are not taking into account that although you provide drawables for different dpis the screen actual size can vary. For example, think on 2 devices with XHDPI screens. They both will use the same drawable, however if the first screen is 720 pixels wide whereas the second screen is 450 pixels wide the XDPI drawable that you provide (lets say it measures 80 pixels) wont look the same in both screens.
What I would do in your case is to use a gridLayout 3x2. Then place the buttons inside the cells and set them to match_parent or wrap_contentdepending on the relative height with size of the cell. That way your layout will adapt to any screen.

Also check this How to make perfect square shaped image/button

Community
  • 1
  • 1
Quark
  • 402
  • 4
  • 15
  • it didn't solve my problem but the UI looks much better with gridLayout. Thanks for that – equitharn May 22 '15 at 10:48
  • If you need my email to ask me something you can do it here :) – Quark May 23 '15 at 18:46
  • Using gridLayout helped by keeping the buttons in place but they didn't help me with re-sizing the images. Should I post the layout file here, so you can tell me where I'm going wrong? – equitharn May 24 '15 at 06:14
  • check this http://stackoverflow.com/questions/24927575/how-to-make-perfect-square-shaped-button – Quark May 24 '15 at 22:57
  • thanks for the comment... Add up that link in your answer and I'll accept the answer... – equitharn May 26 '15 at 13:16
0

Although there isnot enough info to be 100% sure, check in your manifest if you've set inside the Manifest for the targetSdkVersion. If you don't set it it's default value is 1 and that could mean android will ignore some densities that were added later on regardless of the actual device is of big API level. Use the latest api level available (the one you downloaded from the sdk manager)

<uses-sdk 
      android:minSdkVersion="1"
      android:targetSdkVersion="22"/>
TomTsagk
  • 1,474
  • 9
  • 23