I know that there is a lot of gigabytes of information about my problem, I've almost read all of it - official documentation on developer.android.com, posts on XDA-Developers and here, and many other BUT STILL have problem with it and I hope you can explain it to me. So I've an app with dashboard icons on a main-screen, and I need to make that this screen will be looked the same on all existing screens, here is a portrait and land standarts:
To make it I've added to my project a next folders:
And all sizes such as images size, text size and margins I've setted in dimens.xml for each screen resolution, and I was thinking that's enough to see the same picture on different devices. But I was wrong, and in the same resolution but different screen size it's looks different. Here is a 3.2" and 5.1" screens with mdpi:
I didn't get should I add a folders like "values-mdpi-sw320dp" and so on or there is something another way I should know to see same picture on all screens? Is it a right way to set an all sizes in dimens? Please explain it to me. REGARDS.
You don't need to specify all these different sizes to achieve a screen as simple as that one. Simply play a bit around with layouts. For example let's take your first screen. You could use a TableLayout or even a vertical LinearLayout with N LinearLayout inside. At this point simply use weights! Example: want a grid of two rows and three square images for each row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".33" />
<ImageView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".33" />
<ImageView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".33" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".33" />
<ImageView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".33" />
<ImageView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".33" />
</LinearLayout>
Now unfortunately that's still not enough for you. Another thing you might want to accomplish is to still have your images have a square ratio. To achieve that simply extend image view like this:
public class SquaredImageView extends ImageView {
public SquaredImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = width;
setMeasuredDimension(width, height);
}
}
Now simply provide images in the right densities and everything will look exactly as you want
I think this topic is a lot of trouble too. As you said you should use the values-sw320dp-hdpi
, values-sw320dp-xhdpi
, values-sw320dp-xxhdpi
and so on in your application.
I recently did the same on an application I was working on and I found out that the Galaxy S2
read the values-sw320dp-hdpi
, the Galaxy S4
took the values-sw320dp-xxhdpi
and the Galaxy Note
took values-sw320dp-xhdpi
. So yes, declaring these things is a necessity.
You could refer to this as a quick read if you want to. And this application is really helpful as it reveals most of the devices well kept secrets.
The smallest-width qualifier is available only on Android 3.2 and above, if your 5.1" screen is running os version earlier than 3.2, it will not match the right layout.
if both the android version is >= 3.2, the layout_sw600dp or layout_sw720dp 's layout file is not "truly" optimized for it. From the screen shot you provided, the layout's size of some ui element is not optimized right.
First thing first, it doesn't matter your screen size in inch at all. You have to figure out your screen density e.g. 240+dpi for my Sony Xperia Z. Afterwards, you can match them to the closet bucket defined by Android e.g. 240dpi - hdpi.
In your case, the bucket is mdpi. Only 1 set of drawable in drawable-mdpi
will apply to both of your devices.
What you are seeing is the correct behaviour. You might want to re-layout your stuffs to fit the bigger screen e.g. having 5 rows instead of 3. Alternatively, you can draw bigger frames (160dp for each icon instead of 100dp; you need to use DisplayMetrics
and do some calculation) AND use higher-resolution images to fit those frames (these images need to be in the SAME folder drawable-mdpi
though!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With