I don't have an Nexus 5x device, but I'm using Emulator.
Edit: Confirmed from a Nexus 5x user. Its not an Emulator bug.
Problem:
On Nexus 5x app loads incorrect size drawables. While on Nexus 5 is fine.
I have an image original size 1440x2560. Resized it to drawable-xxhdpi - 1080x1920
Log returns me something interesting too:
Nexus 5:
Display Width= 1080 Display Height= 1776
Background Width= 1080 Background Height= 1920
Nexus 5x:
Display Width= 1080 Display Height= 1794
Background Width= 945 Background Height= 1680
My code.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.backgroundisfdupyo">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends Activity {
private static final String TAG = "Main";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
logScreenSize();
}
private void logScreenSize() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int displayW = displayMetrics.widthPixels;
int displayH = displayMetrics.heightPixels;
Log.e(TAG,"displayW= " + displayW + " displayH= "+ displayH);
Drawable bckg = getResources().getDrawable(R.drawable.background);
Log.e(TAG,"Background Width= " + bckg.getMinimumWidth() + " Background Height= "+ bckg.getMinimumHeight());
}
@Override
protected void onStart() {
super.onStart();
toggleHideyBar();
}
public void toggleHideyBar() {
int newUiOptions = 0;
// Navigation bar hiding: Backwards compatible to ICS.
if (Build.VERSION.SDK_INT >= 14) {
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
// Status bar hiding: Backwards compatible to Jellybean
if (Build.VERSION.SDK_INT >= 16) {
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if (Build.VERSION.SDK_INT >= 18) {
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
//END_INCLUDE (set_ui_flags)
}
activity_main.xml
...
<FrameLayout
android:id="@+id/backgroundFrame"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageView
android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background" />
</FrameLayout>
Edit:
Resource Tree as requested.
\drawable-xxxhdpi\background.jpg - 1440 x 2560
\drawable-xxhdpi\background.jpg - 1080 x 1920
\drawable-xhdpi\background.jpg - 720 x 1280
\drawable-hdpi\background.jpg - 540 x 960
\drawable-mdpi\background.jpg - 360 x 640
\drawable-ldpi\background.jpg - 270 x 480
Edit:
https://android-developers.googleblog.com/...
It has a quantized density of 560 dpi, which falls in between the xxhdpi and xxxhdpi primary density buckets. For the Nexus 6, the platform will scale down xxxhdpi assets, but if those aren’t available, then it will scale up xxhdpi assets.
How do I turn it off ? I want my project to ONLY take images from my premade images, I don't want it to scale up/down something.