Android layout dla określonego urządzenia nie pojawia się

0

Przygotowałem dla moich dwóch urządzeń dwa różne layouty. Najpierw sprawdziłem jaką mają szerokość i wysokość w dp poprzez ten kod:

    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics ();
    display.getMetrics(outMetrics);

    float density  = getResources().getDisplayMetrics().density;
    float dpHeight = outMetrics.heightPixels / density;
    float dpWidth  = outMetrics.widthPixels / density;

Pokazało mi to, że pierwsze urządenie ma 360dp width and 592dp height, a drugie 360dp width and 692dp height. Przygotowałem wiec dwa różne layouty w odpowiednich folderach layout-w360dp-h592dp oraz layout-w360dp-h692dp.

Po uruchomieniu programu okazuje się, że nie korzystają z przypisanego do nich layoutu. Urządzenie z 360dp width and 592dp height device korzysta z domyślnego layoutu a urządzenie z 360dp width and 692dp height korzysta z layoutu dla for 360dp width and 592dp height.

Gdzie leży problem? Dziękuję z góry!

0

https://developer.android.com/guide/topics/resources/providing-resources#QualifierRules
https://developer.android.com/guide/topics/resources/providing-resources#BestMatch

App resources overview  |  Android Developers

Available height h<N>dp

Examples:
h720dp
h1024dp
etc.

Specifies a minimum available screen height, in "dp" units at which the resource should be used—defined by the <N> value. This configuration value changes when the orientation changes between landscape and portrait to match the current actual height.

Using this to define the height required by your layout is useful in the same way as w<N>dp is for defining the required width, instead of using both the screen size and orientation qualifiers. However, most apps won't need this qualifier, considering that UIs often scroll vertically and are thus more flexible with how much height is available, whereas the width is more rigid.

When your app provides multiple resource directories with different values for this configuration, the system uses the one closest to (without exceeding) the device's current screen height. The value here takes into account screen decorations, so if the device has some persistent UI elements on the top or bottom edge of the display, it uses a value for the height that is smaller than the real screen size, accounting for these UI elements and reducing the app's available space. Screen decorations that aren't fixed (such as a phone status bar that can be hidden when full screen) are not accounted for here, nor are window decorations like the title bar or action bar, so apps must be prepared to deal with a somewhat smaller space than they specify.

W swoich wyliczaniach nie wziąłeś pod uwagę: "Screen decorations" i pewnie dlatego masz błąd zaokrągleń.

1

@Kubaz: Jak mówi stare przysłowie: "zakładasz majtki przez głowę", mówiąc mniej kolokwialnie: mamy tutaj do czynienia z problemem X / Y. Pytasz się dlaczego assety nie są brane z dobrych folderów a odpowiedź brzmi: layouty oraz assety powinny być tak zrealizowane żeby dopasowały się do rozmiaru ekranu na podstawie jednego pliku. Nie mówię tutaj o tablet <> smartphone tylko że dla każdego smartphona powinieneś mieć jeden layout. Ostatni raz kiedy bawiłem się w custom-hdpi-stuff było dobre 7 lat temu.

1 użytkowników online, w tym zalogowanych: 0, gości: 1