2016-07-25 2 views
0

Ich möchte eine Karte für die Auflistung machen. Aber ich bekomme keine richtige Sichtweise.Ich möchte eine Karte für die Auflistung machen. Aber ich bekomme keine richtige Sicht

Ich möchte Bild auf der linken Seite anzeigen. Auf der rechten Seite des Bildes möchte ich den Namen des Hotels, den Bereich, die Bewertung, die Küche anzeigen.

Aber alles überschneidet sich nun über diesen Code.

Kann mir jemand helfen? Ich lade Bild hoch, was ich von diesem Code gebrauche.

siehe im Bild Name des Hotels, Gebiet, Bewertung, Küche überlappt sich. Wie löst man das? Dies ist der Screenshot, was ich will durch Kartenansicht

. enter image description here

enter image description here

list_row.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    > 
<!--<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/list_row_selector" 
    android:padding="8dp" >--> 

    <!-- Thumbnail Image --> 
    <android.support.v7.widget.CardView 
     android:id="@+id/ly_root" 
     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="wrap_content" 
     android:background="#FEFEFE" 
     android:layout_margin="8dp" 
     app:cardCornerRadius="4dp"> 


    <!--<android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view" 
     android:layout_gravity="center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     card_view:cardCornerRadius="4dp">--> 
    <com.android.volley.toolbox.NetworkImageView 
     android:id="@+id/thumbnail" 
     android:layout_width="120dp" 
     android:layout_height="80dp" 
     android:scaleType="centerCrop" 
     android:layout_marginRight="8dp" /> 

    <!-- Restaurant name --> 
    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:layout_toRightOf="@+id/thumbnail" 
     android:textSize="@dimen/title" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/area" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/name" 
     android:textColor="#D2691E" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:textSize="@dimen/rating" /> 

    <!-- Rating --> 
    <TextView 
     android:id="@+id/average_ratings" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/area" 
     android:textColor="#D2691E" 
     android:layout_toRightOf="@+id/thumbnail" 

     android:textSize="@dimen/rating" /> 

    <TextView 
     android:id="@+id/cuisine" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/average_ratings" 
     android:textColor="#D2691E" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:textSize="@dimen/rating" /> 

    <!-- Genre --> 
    <!-- <TextView 
     android:id="@+id/genre" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/rating" 
     android:layout_marginTop="5dp" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:textColor="@color/genre" 
     android:textSize="@dimen/genre" />--> 
<!-- 
    &lt;!&ndash; Release Year &ndash;&gt; 
    <TextView 
     android:id="@+id/releaseYear" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:textColor="@color/year" 
     android:textSize="@dimen/year" />--> 
    </android.support.v7.widget.CardView> 
</LinearLayout> 
+0

Verwenden Sie eine Kombination aus linearen Layouts in Ihrem Kartenlayout. Es wird helfen, da das Kartenlayout selbst die Anordnung der Ansichten nicht kontrollieren kann –

Antwort

3

Verwenden CardView Kind RelativeLayout

<android.support.v7.widget.CardView 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:id="@+id/ly_root" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="8dp" 
    android:background="#FEFEFE" 
    app:cardCornerRadius="4dp"> 
    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <com.android.volley.toolbox.NetworkImageView 
      android:id="@+id/thumbnail" 
      android:layout_width="120dp" 
      android:layout_height="80dp" 
      android:layout_marginRight="8dp" 
      android:scaleType="centerCrop" /> 

     <!-- Restaurant name --> 
     <TextView 
      android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:layout_toRightOf="@+id/thumbnail" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/area" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/name" 
      android:layout_toRightOf="@+id/thumbnail" 
      android:textColor="#D2691E"/> 

     <!-- Rating --> 
     <TextView 
      android:id="@+id/average_ratings" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/area" 
      android:layout_toRightOf="@+id/thumbnail" 
      android:textColor="#D2691E" /> 

     <TextView 
      android:id="@+id/cuisine" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/average_ratings" 
      android:layout_toRightOf="@+id/thumbnail" 
      android:textColor="#D2691E" /> 
    </RelativeLayout> 

</android.support.v7.widget.CardView> 
+0

Ich muss die Kartenansicht verwenden. Es wird eine einfache Listenansicht erhalten. Es wird wie ein erstes Bild aussehen. Während ich wie ein zweites Bild möchte, sehe ich im zweiten Bild eine Kartenansicht, aber der Text überlappt sich. – user6313669

+0

Überprüfen Sie meinen Update-Code – vinoth12594

+0

Es funktioniert ??? – vinoth12594

1

Im Allgemeinen Ihre CardView sollte nur ein Layout enthalten - die RelativeLayout Sie zuvor verwendet haben. Das CardView selbst kann die Elemente nicht so positionieren, wie Sie es möchten.

Wenn Sie sich die documentation ansehen, werden Sie sehen, dass CardView FrameLayout erweitert, das nur ein Kind enthalten sollte und somit keine Kontrolle über die Positionierung innerhalb des CardView gibt.

0

CardView ist wie ein FrameLayout. Aufeinanderfolgende Elemente in der cardView im Layout werden über dem vorherigen platziert.

Sie können die layout_gravity für "TextView" auf "rechts" einstellen. Es wäre keine perfekte Art, es zu tun. Also, ich schlage vor, die TextView innerhalb eines linearen Layouts mit orientation = "vertical" zu kapseln und die Layout_gravitation von LinearLayout nach rechts zu setzen.

Verwandte Themen