Reputation: 1604
My application have layout, which looks perfect at all devices, except devices with mdpi screen destiny. Activity just doesn't fit to screen on mdpi devices.
So I want to create special dimens.xml for these type of devices. I created "values-mdpi" folder next to my "values" folder, created new dimens.xml into it and set dimens values for mdpi devices.
res/values/dimens.xml:
<resources>
<dimen name="logo_block_height">100dp</dimen>
</resources>
res/values-mdpi/dimens.xml:
<resources>
<dimen name="logo_block_height">50dp</dimen>
</resources>
And ImageView that uses that dimen:
<ImageView
android:layout_width="250dp"
android:layout_height="@dimen/logo_block_height"
android:id="@+id/font_logo" android:adjustViewBounds="false" android:src="@drawable/bg_font_logo"
android:layout_marginTop="20dp" android:layout_marginBottom="20dp"/>
The problem is that values now applied for all devices, not only for mdpi, but for hdpi, xhdpi, xxhdpi too.
I want it to work like that:
If device screen destiny is mdpi or lower - use values from values-mdpi folder
If device screen destiny is MORE than mdpi - use default "values" folder.
How it can be done?
Upvotes: 1
Views: 1174
Reputation: 1604
So I came up with only one solution for that without creating values folder for each screen density.
When at least one "values" folder with destiny qualifiers created android selects the most suitable folder for device screen destiny. This is the reason why it selects "values-mdpi" for everything that bigger or smaller than mdpi.
Also, like ataulm said, there are no sense use screen density qualifiers in that situations. I can have phone with 340x480 with 160dpi where content doesn't fit and Tablet with 1280x800 with 160dpi where there is too much free space.
I solved that by creating Values folder with minimal-height qualifiers. I have folder "values-h480dp" with values for every device with minimum 480 dp availible height and put default values in it. In default "values" folder i put values for devices with small screen.
Now it works like I need:
I sorry for my bad English and hope that this has helped someone.
Upvotes: 2