Ich habe kein Nexus 5x Gerät, aber ich benutze Emulator.Android-Emulator Nexus 5x lädt falsche Zeichengröße?
Bearbeiten: Von einem Nexus 5x-Benutzer bestätigt. Es ist kein Emulator-Fehler.
Problem:
Auf Nexus 5x App lädt falsche Größe Drawables. Während auf Nexus 5 ist in Ordnung.
Ich habe ein Bild Originalgröße 1440x2560. Resized es ziehbar-xxhdpi - 1080x1920
Log gibt mir auch etwas Interessantes:
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
Mein 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>
Bearbeiten:
Resource Tree wie angefordert.
\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/...
Es hat eine Dichte von quantisierten 560 dpi, die zwischen dem xxhdpi und xxxhdpi Primärdichte Eimern in fällt. Für das Nexus 6 wird die Plattform xxxhdpi-Assets herunterskalieren, aber wenn diese nicht verfügbar sind, werden die xxhdpi-Assets vergrößert.
Wie schalte ich es aus? Ich möchte, dass mein Projekt NUR Bilder von meinen vorgefertigten Bildern aufnimmt, ich möchte nicht, dass es etwas vergrößert/verkleinert.
versuchen Sie scaleType 'fitCenter' oder zeigen Sie Ihre Res Ordner Baum – egoldx
Sieht aus wie Ihre ImageView Höhe nicht Match_parent. Versuchen Sie es mit match_parent zu setzen. Und ich sehe Einschränkungen in Ihrem FrameLayout, das heißt, dass Sie FrameLayout in ConstraintLayout verwenden, warum? Versuchen Sie eine von ihnen zu verwenden – Skullper
@PavliukR Ich nahm es aus FrameLayout, es füllte den Bildschirm wie auf Nexus 5x, aber das Protokoll sagt immer noch, dass geladene Bacground Bild Breite = 945 Höhe = 1680 ist, wo es wie Nexus 5 laden sollte Breite = 1080 Höhe = 1920. Ich denke, es hat nur das Bild gestreckt. – paakjis