2017-10-08 4 views
0

Mon but exact est de réduire la taille (hauteur et largeur) de l'image légèrement (car la taille de wrap_content est trop grande) et de le placer au centre de Écran de démarrage. Mais peu importe ce que je fais, ça ne se trouve pas au centre tant que j'utilise wrap_content ou match_parent. Voici le code que j'utilise.Comment redimensionner la taille et placer l'image au centre de l'écran de démarrage de l'application Android

<?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.yoalfaaz.yoalfaaz.SplashScreen"> 

    <ImageView 
     android:layout_width="300dp" 
     android:layout_height="300dp" 
     tools:layout_editor_absoluteY="25dp" 
     tools:layout_editor_absoluteX="25dp" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/ss" /> 
</android.support.constraint.ConstraintLayout> 

Quelle serait la meilleure façon d'y aller depuis la mise en taille de préfixe comme je l'ai fait ne pas laisser s'adapter aux écrans plus grands (comprimés) pour la plupart.

+0

Qu'est-ce que le panneau parent? Linéaire? Relatif? –

+0

@ d.moncada pouvez-vous s'il vous plaît dire comment vérifier cela. Je suis toujours un débutant dans Android alors je suis assez confus. Bien que j'ai édité la question pour fournir tout le contenu sur le fichier activity_splash_screen.xml, peut-être que cela peut aider. –

+0

votre édition montre ce dont j'avais besoin, merci –

Répondre

1

Puisque vous utilisez un constraintlayout pour votre panneau parent, essayez ce qui suit:

<?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.yoalfaaz.yoalfaaz.SplashScreen"> 
    <ImageView 
     android:layout_width="300dp" 
     android:layout_height="300dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:src="@drawable/ss" /> 
</android.support.constraint.ConstraintLayout> 
+0

Votre réponse a parfaitement réussi. Pouvez-vous s'il vous plaît dire exactement ce que vous avez fait afin que je puisse aussi mieux le comprendre. :) –

+1

Puisque vous utilisez un ConstraingLayout, j'ai ajouté des contraintes à tous les côtés de l'image (toLeftOf, à RightOf, toTopOf et toBottomOf). Cela le forcera à être au centre. –

+0

Je l'ai eu, merci beaucoup pour votre réponse. –

0

essayez d'ajouter votre ImageView dans le parent de linearLayout ou la disposition relative.

puis ajoutez ImageView avec android: scaleType = "center" et n'oubliez pas d'ajouter centerInParent = true si vous utilisez relative ou android: gravity = "center" pour linearLayout.

1

si vous utilisez LinearLayout en tant que parent, vous devez définir la gravité comme centre à votre LinearLayout mère pour mettre les enfants en center.As below

 <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:orientation="vertical"> 
        <ImageView 
         android:layout_width="300dp" 
         android:layout_height="300dp" 
         android:layout_gravity="center" 
         tools:layout_editor_absoluteY="25dp" 
         tools:layout_editor_absoluteX="25dp" 
         android:src="@drawable/ss" 
         /> 
       </LinearLayout> 
// if you are using RelativeLayout then : 
     <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <ImageView 
      android:layout_width="300dp" 
      android:layout_height="300dp" 
      android:layout_gravity="center" 
      tools:layout_editor_absoluteY="25dp" 
      tools:layout_editor_absoluteX="25dp" 
      android:src="@drawable/ss" 
      android:layout_centerInParent="true" 
      /> 
    </RelativeLayout> 
+0

Votre réponse est également parfaite, j'ai juste besoin de changer la mise en page de contrainte à linéaire ou relatif. –