2017-11-04 1 views
0

Ich habe versucht, ein cardview zu erstellen, das aus fünf Elementen in einem Fragment besteht. Die Kartenansichtsposition befindet sich jedoch immer oben im Layout. Ich habe versucht, Rand und Ausrichtung zu verwenden, aber es hat nicht funktioniert. Wie ändere ich die Position des Cardview?Wie ändere ich die Kartenansichtsposition zum Ende des Tablayouts?

Hier ist meine card_item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="85dp" 
android:orientation="vertical" 
android:id="@+id/my_relative_layout" 
> 


<android.support.v7.widget.CardView 
    android:id="@+id/card_view" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginBottom="8dp" 
    android:backgroundTint="#E3F0F5" 
    android:layout_centerVertical="true" 
    card_view:cardCornerRadius="5dp" 
    card_view:elevation="14dp" 
    > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:id="@+id/iv_image" 
      android:src="@drawable/avatar1" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="10dp" 
      /> 

     <TextView 
      android:textColor="#95989A" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/tv_text" 
      android:layout_toRightOf="@+id/iv_image" 
      android:gravity="center"/> 

     <TextView 
      android:textColor="#95989A" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/tv_blah" 
      android:text="Another RV Fragment" 
      android:layout_below="@+id/tv_text" 
      android:layout_toRightOf="@+id/iv_image" 
      android:layout_toEndOf="@+id/iv_image"/> 

    </RelativeLayout> 

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

</RelativeLayout> 

Hier ist meine activity_pendaftar.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.martin.app.donorkuyadmin.PendaftarActivity" 
android:background="@drawable/background4"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <include 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     layout="@layout/toolbar_pendaftar"> 
    </include> 

    <android.support.design.widget.TabLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tablayout" 
     app:tabMode="fixed" 
     app:tabGravity="fill"> 
    </android.support.design.widget.TabLayout> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/viewpager"> 
</android.support.v4.view.ViewPager> 

</RelativeLayout> 

Das ist mein Screenshot: enter image description here

+0

Fügen Sie bitte die Hauptlayout-XML-Datei hinzu. –

+0

@vikashkumarpandey Okay –

Antwort

1

Geben Sie ein id auf Ihre AppBarLayout (sagen wir, id = action_bar) und dann fügen Sie einfach layout_below="@id/action_bar" zu Ihrem ViewPager:

<android.support.v4.view.ViewPager 
    android:layout_below="@id/action_bar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/viewpager"> 
</android.support.v4.view.ViewPager> 
0

Bewegen Sie include Anweisung außerhalb des appbarlayout und Richte es wie folgt auf den Grund der Eltern aus:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.martin.app.donorkuyadmin.PendaftarActivity" 
    android:background="@drawable/background4"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 


     <android.support.design.widget.TabLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/tablayout" 
      app:tabMode="fixed" 
      app:tabGravity="fill"> 
     </android.support.design.widget.TabLayout> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/viewpager"> 
    </android.support.v4.view.ViewPager> 

    <include 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     layout="@layout/toolbar_pendaftar" 
     android:layout_alignParentBottom="true"> 
    </include> 

</RelativeLayout> 
+0

Es hat nicht funktioniert. Es ändert nur die Position meiner Symbolleiste, nicht die Kartenansicht: D –

1

Verwendung Coordinator Layout statt Relative Layout und setzen layout_behavior Eigenschaft in Sicht Pager zu appbar_scrolling_view_behavior.

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.Toolbar 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <include 
     layout="@layout/toolbar_pendaftar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tablayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabGravity="fill" 
     app:tabMode="fixed"></android.support.design.widget.TabLayout> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</android.support.design.widget.CoordinatorLayout> 
Verwandte Themen