Custom HDPI controls are invisible - android

I have an app, which provides a switchable set of night mode (red) controls using a custom Theme. The controls are in the Shared Preferences view. I have copied and colored all of the necessary images for my controls from Android git sources' hdpi and mdpi folders. The red theme works perfectly fine on the 160 dpi screen (480x800 Android 3.2), but on the 240 dpi one (480x854 Android 2.1) custom check boxes and radios are invisible, they do not occupy any space on the line with label either. Though the drop down list control on a simple linear view seems to be shown perfectly fine. The only difference I can see is that the later one has .9.png images.
What is wrong and how to fix that?

HURRAY! Found the solution by an accident. I have added a hidden checkbox item to one of the first views of my application, and all of the styled checkboxes magically appeared as they should be in every other view! I believe it's a bug in the 2.1 version of Android. I saw something like that mentioned once while googling for the problem here. It might be irrelevant though.

Related

How to know all the dimens.xml(hYYYdp) files I have to create to support all the screen sizes?

I am a little bit desperate because I'm trying to know how can I know the exact list of different dimens.xml(hYYYdp) I have to create in order to support all the screen sizes. I think I have already seen all the related questions to mine but none of them has helped me to solve this doubt. This is the most related question that hasn't solved my doubt: How to define dimens.xml for every different screen size in android? .
To give you some context. The reason of having different values according to the screen size is because I have a ConstraintLayout with some items that have Top and Bottom margin and in some devices that margin is not looking good. In this post I made, someone suggested me to use different margin values according to the screen size: How to solve TextView being cropped in small devices because of layout margin?
I have thought that as the margin is dependent of the height of the device (as I am using only Top and Bottom margin) I would have to create a list of different dimens.xml files according to the height of the device (hYYYdp).
The real concern I have is that I don't know how many dimens.xml files I have to create to support all the screen sizes. What I have been doing is creating some specific dimens.xml files that are working for specific devices, but I think there has to be a general list of all the dimens.xml files that have to be created to support all the screen sizes.
For example, what I have been doing is to look the test devices of Android Studio one by one and create specific dimens.xml files for them. This is the process I have followed to create a specific dimens file:
Example:
1- First I have seen the list of the test devices of Android Studio, for example let's take this one:
2- After this, I have calculated the dp of the height of this specific test device:
240x400px (ldpi) device. So the height's dp is = 400/(120(ldpi)/160)== 533.33dp
3- Finally, I have added the dimens.xml(hYYYdp) correspondent to this specific device with the specific margin value that is looking good:
I have repeated this process for most of the test devices of Android Studio but as a result, I have a list of specific devices but I think there will remain many devices without being supported as not all the Android devices are in the Android Studio test devices list. I hope you have understand what I am trying to explain.

How to add screen layouts for different screen sizes in android? (Update 2020)

I tested my application for screen sizes for 6 inches - 6.5 inches(on a one plus 6t/7t) and above and it's scaling the UI elements properly for it. But when I tested the application for screen sizes of 5 - 5.5inches, it's going out of the constraints and off the screen.
These are the things that I have tried:
Having wrap_content and match_parent with most of the UI elements(Textviews, Buttons to name a few)
Using constraint_layout which is the default layout in Android Studio 3.0 with all the constraints set for every element
I also tried understanding this document but I could not clearly understand this
Lastly, I came across their solution of having a different screen layout for different screen size. For this, what would I have to do? Create a new Layout and copy my Design XML text in the newly created layout and adjust scaling accordingly or is there a better approach for doing so?
Also, any other suggestions or any other approach to solve this would also help.
Edit 1:
So I figured something out, The UI is not setting correctly for xxhdpi resolutions. To compare, two screen sizes of similar sizes (1080x1920) having 420dpi and xxhdpi resolutions, the former works correctly but the latter does not. Any clues on how can I create or deal with xxhdpi resolutions?
[try with this,you can update AS]
[1]: https://i.stack.imgur.com/oLqHI.png

Scale tablet layout to phone

I have a (RelativeLayout) layout xml that was designed to work for 10 inch tablets. I now want the very same layout to be displayed when the app runs on a phone. Instead of it being only displayed partly, I want it to be scaled, so that the structure is the same, just everything a bit smaller.
I have already:
Searched the web - without a result
Read about LayoutInflaters - but have no idea where I could set a scale there
Tried to "override" the defaultWindow's density using Reflection - without a result
Please note that I am aware that this is bad practice, but it's just a personal project and I am curious to know if this is possible.
Any help is highly appreciated!
EDIT: What I want is to really scale the screen as a whole.
I am not the author of the original layout, as it's an open source project for tablets that I want to use on my phone.
Here is the source: https://github.com/amigold/Gui2Go
The layout I am talking about is main.xml.
My reputation is too low to ask you to include a sample layout, and my proposal does not use the exact same layout. However, You can create layouts with the same id tags and filename.xml having the 10 inch tablet version in the folder res/layout-sw600dp and the phone version in res/layout. The layout in /layout-sw600dp will be automatically used for larger screens & the layout in /layout will be used for smaller screens. You will not have to change your setContentView() call at all.
see: http://developer.android.com/guide/practices/screens_support.html

Widgets appear smaller in Eclipse than on the phone

I am currently putting together an application for my HTC Evo 3D phone which has a screen resolution of 960x540. I have set up a custom layout configuration for designing the interface at this resolution. When in this configuration the widgets (texts views, seek bars etc.) appear small and compact, sparse on the screen. Whereas when I launch the application on my phone the buttons are considerably larger and fill the screen more. Is there some setting in Eclipse that will allow me to view the layout in the editor exactly as it would appear on my phone, allowing for easier design of the interface.
Many thanks, Mat.
with relevant code would be easer to help, however, if you are using dp unit measure, sizes will change according to resolution:screensize, not just resolution. I think also a "wrap_content" given to a textview/button etc. would change in size, because font size would be in sp. So, look if there is any emulator configuration that fits real device resolution AND screen size.
Take a look here for more info about measure units.
EDIT
so are you seeing it in eclipse in the graphical layout of yourlayout.xml? on the top bar of that window there's a dropmenu for display configurations, change it to see the layout in different screens (I don't see any 960x540 btw). however, if you really want to develop for one single device is a matter, but if you're going to release the app for different devices, you need some strategy to make flexible layouts. this is very useful.

Android - QVGA screen hides some pixels

I have a problem with missing pixels on QVGA screen on Android (all versions including 2.2). The original problem was with LinearLayout and margin="1px". It was OK on the normal screen but on QVGA there was sometimes no space between GUI controls, like if margin="0px" and not 1px. So I tried to make the example simple (to be sure that it is not a LinearLayout bug), I have just put transparent (height = 10px) and white (height = 1px) images into ImageViews into the main screen. 25% of the white images are not shown on the QVGA screen. The behaviour on the normal screen is OK. The screenshots are from the emulator but the problem exists on real devices too.
See screenshots on my web page.
Is it an Android bug? Can I do anything with it? Note that my original problem was with LinearLayout and margin="1px". Is there something like margin="1px_that_is_not_hidden"? (pt, dp, dip, ... don't seem to be solution)
Many thanks for a reply.
You are probably in a compatibility mode, where Android is attempting to scale your dimensions for you, rather than thinking that you know what you're doing. It's been ages since I targeted a QVGA device, so I forget the precise details. However, I recommend you read the multiple-screen-size instructions. In particular, you probably need to set android:anyDensity="true" in your <supports-screens> element.

Categories

Resources