Einschränkung layout nicht zeigen Bild aus der Bildansicht, wenn die app läuft
Ich versuche, fügen Sie einige Bilder von Bildansicht in Android-Aktivität(ConstraintLayout),
auf Android-Studio-Vorschau-Bildschirm, zeigt Bilder richtig, aber bei mir läuft die app auf einem echten Gerät oder emulator, es zeigt nicht das Bild.
Unten ist der code mit dem ich arbeite,
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vchamps.android.staffast.ProfessionalsCalc"
android:background="@color/colorPrimary">
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guidelineVertical1"
app:layout_constraintGuide_percent="0.1"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="39dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guidelineVertical2"
app:layout_constraintGuide_percent="0.25"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="96dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guidelineHorizontal"
app:layout_constraintGuide_begin="87dp"
android:orientation="horizontal"
tools:layout_editor_absoluteY="87dp"
tools:layout_editor_absoluteX="0dp" />
<ImageView
android:visibility="visible"
android:id="@+id/imgRate"
android:layout_width="@dimen/rates_icon_size"
android:layout_height="@dimen/rates_icon_size"
app:srcCompat="@drawable/icon_rates"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal"
android:layout_marginTop="27dp"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
/>
<ImageView
android:visibility="visible"
android:id="@+id/imgSchedule"
android:layout_width="@dimen/rates_icon_size"
android:layout_height="@dimen/rates_icon_size"
app:srcCompat="@drawable/icon_schedule"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@+id/imgRate"
app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
android:scaleType="fitCenter"
/>
<ImageView
android:visibility="visible"
android:id="@+id/imgPayout"
android:layout_width="36dp"
android:layout_height="36dp"
app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical1"
app:srcCompat="@drawable/icon_payout"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/imgSchedule"
android:scaleType="fitCenter"
/>
<TextView
android:id="@+id/tvRate"
style="@style/fontRateScreenTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="33dp"
android:text="Industry Leading Rates"
app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical2"
app:layout_constraintTop_toTopOf="@+id/guidelineHorizontal" />
<TextView
android:id="@+id/tvSchedule"
style="@style/fontRateScreenTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:text="Flexible Schedule"
app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical2"
app:layout_constraintTop_toTopOf="@+id/tvRate" />
<TextView
android:id="@+id/tvPayout"
style="@style/fontRateScreenTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:text="Quick and Easy Payout"
app:layout_constraintLeft_toLeftOf="@+id/guidelineVertical2"
app:layout_constraintTop_toTopOf="@+id/tvSchedule" />
<Button
android:id="@+id/btnWork"
style="@style/ButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="CLICK ME"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
</android.support.constraint.ConstraintLayout>
Den UI-Preview in Android Studio ist als unten,
Können wir sehen, dass 3 Bilder bekommen, die hier angezeigt werden,
Aber wenn ich die Anwendung auf einem emulator oder auf einem echten Gerät, ist es nicht mit den 3 Bildern. Unten ist der screenshot des emulators,
- Wert von " @dimen/rates_icon_size: 36dp
- Drei Bilder, Abmessungen,
- icon_rates : 87x59 Pixel
- icon_schedule : 88x78 Pixel
- icon_payout : 60x82 Pixel
Bitte helfen Sie mir, indem Sie die Auflösung der Abfrage, vielen Dank im Voraus.
- Ich hatte das gleiche problem. Bitte stellen Sie sicher, Sie sind call
super.onCreate(savedInstanceState)
vorsetContentView(R.layout.your_layout)
in Ihre java-Klasse. Ich löste es auf diese Weise. - Ja, ich habe bereits genannt, es auf die gleiche Weise.
Du musst angemeldet sein, um einen Kommentar abzugeben.
In der Bildansicht anstelle von srcCompact verwenden src
statt
srcCompat
imAppCompatImageView
statt der Bildansicht. Ich bin mir nicht sicher über den Grund.verwenden
android:src="@drawable/icon_rates"
irgendwannapp:srcCompat="@drawable/icon_rates"
nicht funktionieren.Ich denke, deine Bilder sind das problem. Zumindest ist es nicht eine elegante Lösung.
Wenn sollte Ihre app auf verschiedenen Geräten, dann sollten Sie verwenden Android-Vektor-Drawables anstelle der normalen PNG Bilder. Vektor-drawables anstelle von bitmaps reduziert die Größe der APK, da die gleiche Datei kann in der Größe verändert werden, die für unterschiedliche Bildschirmauflösungen ohne Verlust der Bildqualität.
Wenn Sie möchten, verwenden Sie Ihre Bilder, dann sollten Sie konvertieren Sie zuerst in das SVG-format (mit Inkscape zum Beispiel, es ist kostenlos) und dann in den Vektor Drawable-format mit diese kostenloses online-tool.
Die zweite Lösung wäre die Verwendung Material Design Icons. Sie sind entwickelt mit vielen Designern, um sicherzustellen, dass eine gute user experience und Sie sind auch in der Vektor-drawable-format.
Ich habe versucht den code aus mit dem Vektor drawables und der app ist die Anzeige der Bilder ohne Probleme.