0

Ich verwende eine CardView mit ImageView in RecyclerView. Unten ist XML-Code.CardView mit ImageView in RecyclerView füllt nicht Bildschirm

List Item (CardView) xml:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:elevation="20dp" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

<ImageView 
     android:id="@+id/feed_cradImage" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/mysteps1"/>  
</android.support.v7.widget.CardView> 

Verwendung in einem RecyclerView:

<android.support.v7.widget.RecyclerView 
      android:id="@+id/home_recyclerView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     </android.support.v7.widget.RecyclerView> 

Aber ich einige Probleme bin vor.

1 => Ich habe gesetzt layout_width als "match_parent" von CardView und ImageView. Aber, immer noch CardView füllt nicht den gesamten Bildschirm und zeigt einen Rand in der rechten Seite.

enter image description here

2 => Wenn die Bildgröße in der Breite klein ist, dann CardView wird nach Bildgröße schrumpfen. Ich möchte, dass die Karte nicht schrumpft, auch wenn sie leer ist oder ein kleines Bild enthält.

enter image description here

Hinweis: Ich verwende Picasso für Bilder vom Server abgerufen werden.

+2

android hilft: Scaletype = "fitXY" oder Android: Scaletype = "centerCrop" in ImageView –

Antwort

2

fügen Sie diese zu Ihrer Image

android:adjustViewBounds="true" 
android:scaleType="centerCrop" 
0

Es scheint mir, dass das Image die CardView richtig füllt, aber das Bild füllt nicht richtig das Image. Sie könnten versuchen, dies zu ermitteln, indem Sie Hintergrundfarben für beide Elemente festlegen und sehen, welcher Hintergrund angezeigt wird. diese

das Problem zu lösen, versuchen:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:elevation="20dp" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

<ImageView 
     android:id="@+id/feed_cradImage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/mysteps1" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop"/>  
</android.support.v7.widget.CardView> 
+0

Bild füllt die ImageView, aber weiß nicht, warum das Ergebnis gleich ist. –

+0

Haben Sie meine Version von yout xml ausprobiert? Wenn ja, ist das Ergebnis dasselbe? –

0

eine Höhe reduzieren und das Ergebnis überprüfen, ob es

app:elevation="4dp"