As mentioned earlier, my approach will also make full use of device-independent components, such as paddins, fields, and relativelayouts, in combination with the device’s stand-alone puxels.
To be honest, I hope that I'm not the only one, but I fully use DIP (device independent pixels) and relative layout and such ... reduced my activity layout files to 1 by activity, not 3 different types for HDPI , MDPI and LDPI.
if you are really concerned about the aspect ratio, you can always call up the screen properties in the pixels of the device and carry out the corresponding calculations based on these numbers. You can call this at the very beginning of the onCreate method of your first action.
Display display = getWindowManager().getDefaultDisplay(); int displayWidth = display.getWidth(); int displayHeight = display.getHeight();
this will give you the width and height values of your equipment in pixels. In my opinion, the true reason why you have chosen more than three types of layouts is to provide a clear image resolution.
Using these numbers, you can do some internal logic that calculates the type of resolution images to load in some widgets. Thus, you save you from having to do 3 times the same layout ....
can be explained a bit cryptic, but the main thing to overcome various device resolutions is to work a lot with:
- relativelayouts
- Device Independent Pixels
You can also define DIP in the XML layout so that each component looks the same on all types of devices.
maybe a stupid example, but hey, it worked for me :-) here below I tried to get the size of the text in text form relative to one on all devices. You can call the "TypedValue" class and select one of the many public variables offered there. Since I wanted the TextView everywhere to be the same relative size, I used the following code:
someTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
you must indicate how large the value is in the DIP. TypedValue can be used in many widget or activity components that require an INT value for dimension properties. Play with it and you will see that life is much simpler: -p
hope this answer helps a little