2017-07-04 4 views
0

Ich versuche, meine recyclerview unter dem cardview zu setzen, aber ich don t wissen genau die Lösung:kann nicht recyclerview unter cardview einstellen

Mein Layout:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/coordinatorLayout" 
    xmlns:card_view="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_refresh" 
     android:layout_width="match_parent" 
     android:layout_height="180dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


     <android.support.v7.widget.CardView 
      android:id="@+id/card_view" 
      android:padding="5dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:cardCornerRadius="4dp" 
      card_view:cardCornerRadius="4dp"> 


      <RelativeLayout 
       android:id="@+id/rel" 
       android:padding="10dp" 
       android:layoutDirection="ltr" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:id="@+id/txt_competition" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/X" 
        android:textColor="#000000" 
        android:textAlignment="center" 
        android:textSize="18sp" 
        android:layout_marginTop="20dp" 
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true" 
        /> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_marginLeft="10dp" 
        android:layout_marginStart="10dp" 
        android:layout_gravity="start" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/linearLayout2"> 


        <ImageView 
         android:id="@+id/image_team1" 
         android:layout_width="60dp" 
         android:layout_height="60dp" 
         android:adjustViewBounds="true" 
         android:layout_gravity="start" 
         android:src="@drawable/placemahdi" 
         android:scaleType="fitXY" 

         /> 

        <TextView 
         android:id="@+id/name_team1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="15sp" 
         android:layout_gravity="center" 
         android:textAlignment="center"/> 


       </LinearLayout> 

       <LinearLayout 
        android:layout_alignParentEnd="true" 
        android:layout_alignParentRight="true" 
        android:orientation="vertical" 
        android:layout_marginRight="10dp" 
        android:layout_marginEnd="10dp" 
        android:id="@+id/linear_team2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="end"> 


        <ImageView 
         android:id="@+id/image_team2" 
         android:layout_width="60dp" 
         android:layout_height="60dp" 
         android:layout_gravity="end" 
         android:src="@drawable/placemahdi" 
         android:adjustViewBounds="true" 
         /> 

        <TextView 
         android:id="@+id/name_team2" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:textAlignment="center" 
         android:textSize="15sp" /> 



       </LinearLayout> 



       <TextView 
        android:textAlignment="center" 
        android:layout_centerInParent="true" 
        android:text="توقع النتيجة" 
        android:id="@+id/divide" 
        android:textColor="@android:color/holo_red_light" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="14sp" /> 




       <Button 
        android:id="@+id/button_vote0" 
        android:layout_width="50dp" 
        android:layout_height="wrap_content" 
        android:background="@drawable/ic_forwardplus" 
        android:textStyle="bold" 
        android:layout_alignParentBottom="true" 
        android:layout_alignLeft="@+id/between" 
        android:layout_alignStart="@+id/between" /> 
       <Button 
        android:id="@+id/button_vote1" 
        android:layout_width="50dp" 
        android:layout_height="wrap_content" 
        android:background="@drawable/ic_backplus" 
        android:textStyle="bold" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentStart="true" /> 

       <TextView 
        android:id="@+id/between" 
        android:textSize="14sp" 
        android:text="0" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/button_vote1" 
        android:layout_alignRight="@+id/button_vote1" 
        android:layout_alignEnd="@+id/button_vote1" 
        /> 
       <Button 
        android:id="@+id/button_vote2" 
        android:text="X" 
        android:layout_centerHorizontal="true" 
        android:textColor="#FFFFFF" 
        android:layout_alignParentBottom="true" 
        android:textStyle="bold" 
        android:background="@drawable/round_button" 
        android:layout_width="50dp" 
        android:layout_height="wrap_content" /> 

       <Button 
        android:id="@+id/button_vote01" 
        android:layout_width="50dp" 
        android:layout_height="wrap_content" 
        android:background="@drawable/ic_backplus" 
        android:textStyle="bold" 
        android:layout_alignParentBottom="true" 
        android:layout_alignRight="@+id/between1" 
        android:layout_alignEnd="@+id/between1" /> 
       <Button 
        android:id="@+id/button_vote10" 
        android:layout_width="50dp" 
        android:layout_height="wrap_content" 
        android:background="@drawable/ic_forwardplus" 
        android:textStyle="bold" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentEnd="true" /> 

       <TextView 
        android:id="@+id/between1" 
        android:text="0" 
        android:textSize="14sp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignBaseline="@+id/button_vote10" 
        android:layout_alignLeft="@+id/button_vote10" 
        android:layout_alignStart="@+id/button_vote10"/> 


      </RelativeLayout> 


     </android.support.v7.widget.CardView> 
    </android.support.v4.widget.SwipeRefreshLayout> 


    <RelativeLayout 
     android:id="@+id/re2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layoutDirection="ltr"> 


     <android.support.v4.widget.NestedScrollView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

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


    </RelativeLayout> 
</android.support.design.widget.CoordinatorLayout> 

ich versucht habe, die „RE2 einstellen "Die relative Schwerkraft, um es zu zentrieren, funktioniert auf vielen Android-Handys, aber auf einem kleineren Bildschirm verstecken sich einige der Recyclerview-Teile unter der Kartenansicht.

Ich habe auch versucht, die Schwerkraft nach unten einstellen, so dass es von unten beginnt mit Margin = 15dp aber auch dort ist eine Menge Leerräume zwischen recyclerview und cardview

Dies ist ein Screenshot für das Layout:

enter image description here

Wie kann ich die Recyclerview so einstellen, dass sie direkt unter dem Cardview startet?

+0

Verwenden Sie 'CoordinatorLayout' aus einem bestimmten Grund? –

+0

Nein, ich habe es standardmäßig verwendet @RohanStark –

+0

Bitte sehen Sie meine Antwort. Und Sie können mehr über 'LinearLayout' [hier] lesen (https://developer.android.com/reference/android/widget/LinearLayout.html). –

Antwort

1

Der Grund, dass Ihre Ansichten sich überlappen, liegt an der CoordinatorLayout. CoordinatorLayout erweitert eine FrameLayout. Diese dienen dazu, Ansichten zu überlagern, die sich überschneiden.

Was Sie brauchen, ist ein ListView. Es wurde speziell entwickelt, um Kinder in Listen in der Reihenfolge anzuzeigen, in der sie in der XML-Datei hinzugefügt wurden. Also, wenn Ihr CoordinatorLayout keinen anderen Zweck erfüllt, dann ändern Sie es zu einem LinearLayout. So etwas wie das Folgende: -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/linearLayout" 
    xmlns:card_view="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_refresh" 
     android:layout_width="match_parent" 
     . 
     . 
     . 
     . 

</LinearLayout> 
+0

Dank @Rohan es funktionierte perfekt Ich wusste nicht, die ganze Frage war über CoordinatorLayout. Ich habe es jetzt verstanden –

+0

Kein Problem! Froh, dass ich helfen konnte –

Verwandte Themen