Je travaille sur un design. Et il y a un linearlayout pour utiliser des poids. À l'intérieur des mises en page, il y a ImageViews. ImageViews Afficher les images hors cours mais chaque image a un rapport d'aspect différent. Ensuite, je souhaite utiliser ImageView Scaletype Propriété pour la couverture de l'image sur toute la surface de l'image de l'image. Mais rien n'a changé. Dans Android Studio Design Aperçu Il fonctionne, mais lorsque nous installons le simulateur d'applications ou le périphérique réel; rien ne change. Vous pouvez trouver un code XML ci-dessous;
attendre vos réponses; Merci. P>
<LinearLayout 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" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".MainActivity" tools:showIn="@layout/app_bar_main" android:orientation="vertical" android:weightSum="12" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:paddingTop="0dp" android:layout_weight="3" android:weightSum="3" > <ImageView android:id="@+id/img3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_margin="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_weight="1.5" android:adjustViewBounds="true" android:padding="0dp" android:scaleType="center" android:src="@drawable/tarot" /> <ImageView android:id="@+id/img4" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentRight="true" android:adjustViewBounds="true" android:layout_margin="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_weight="1.5" android:padding="0dp" android:scaleType="fitXY" android:src="@drawable/sorusor" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:paddingTop="0dp" android:layout_weight="3" android:weightSum="3" > <ImageView android:id="@+id/img3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_margin="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_weight="1.5" android:adjustViewBounds="true" android:padding="0dp" android:scaleType="center" android:src="@drawable/tarot" /> <ImageView android:id="@+id/img4" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentRight="true" android:adjustViewBounds="true" android:layout_margin="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_weight="1.5" android:padding="0dp" android:scaleType="fitXY" android:src="@drawable/sorusor" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="horizontal" android:paddingTop="0dp" android:layout_weight="3" android:weightSum="3" > <ImageView android:id="@+id/magicBallBtn" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_weight="1.5" android:padding="0dp" android:scaleType="fitXY" android:adjustViewBounds="true" android:src="@drawable/magicballbtn" /> <ImageView android:id="@+id/burcbuton" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentRight="true" android:adjustViewBounds="true" android:layout_margin="0dp" android:layout_marginLeft="0dp" android:layout_marginTop="0dp" android:layout_marginRight="0dp" android:layout_weight="1.5" android:padding="0dp" android:scaleType="fitXY" android:src="@drawable/burcbtn" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3" android:orientation="vertical" android:paddingTop="10dp" > <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/anaekranbutontasarim" android:paddingTop="20dp" /> <TextView android:layout_width="180dp" android:layout_height="40dp" android:layout_gravity="center_horizontal" android:background="@drawable/btntasarim1" android:drawableLeft="@drawable/baseline_star_black_24" android:text="Kredi Al" android:textStyle="bold" android:textSize="20dp" android:textColor="#fff" android:textAlignment="center" android:paddingVertical="5dp" android:paddingLeft="15dp" android:paddingRight="15dp" android:layout_marginTop="15dp" /> <TextView android:layout_width="150dp" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:layout_gravity="center_horizontal" android:text="Kalan Kredi: 100" android:textColor="@color/colorLight" android:textStyle="bold" android:textSize="20dp" /> </LinearLayout> </LinearLayout>
3 Réponses :
Utilisez
android:scaleType="centerCrop"
J'essaie toutes les options d'eux; Centercrop, FitXy, Centre .. tout. Rien ne change sur l'image. @Sajith
En réalité, Scaletype = FITXY CODE> et
SCERETYPE = CENTRE CODE> sont assez différents. p>
FITXY code> va avoir notre hauteur fixe, puis il va à l'échelle de notre image remplissant la largeur. Vous gardez le rapport de l'image de l'image tout en gardant la hauteur à une certaine taille, mais laissez-la modifier la largeur en conséquence, nous sommes donc en mesure de contrôler la taille de l'image (type de) et de maintenir le rapport de format en même temps. . p>
Centre CODE> Centre juste l'image sans l'échec. Si vous ajoutez
ajusterviews = true code>, vous allez conserver le rapport de format de l'imageView avec RéglageVoustine la taille de l'imageView (pas l'image) conserve le rapport de format de l'image. p>
Merci de réponse, mais ici, mon problème est que toutes les options de typeType ne fonctionnent pas. J'essaie toutes les options mais je n'ai jamais vu de changement. @underwood
@Emreerol je pense que le problème est de la taille de votre image match_parent code>. Essayez de prendre une taille fixe et normalement tous les scaltipes fonctionneront
Je n'essaie rien de changer. @underwood
Supprimer