2017-11-04 28 views
0

フラグメント内に5つのアイテムからなるカードビューを作成しようとしました。ただし、カードビューの位置は常にレイアウトの一番上にあります。私は余白を使用して整列を試みたが、うまくいかなかった。 カードビューの位置を変更するにはどうすればよいですか?ここで カードレイアウトの位置をtablayoutの下部に変更するにはどうすればよいですか?

は私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> 

がある私の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> 

これが私のスクリーンショットです: enter image description here

+0

メインレイアウトxmlファイルを追加してください。 –

+0

@vikashkumarpandeyいいえ –

答えて

1

( action_bar =たとえば、ID)あなたのAppBarLayoutidを与え、その後、単にあなたのViewPagerlayout_below="@id/action_bar"を追加します。

<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
appbarlayout外にあなたの include声明を移動し、

それを親の底に合わせる:

<?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

動作しませんでした。それはちょうど私のツールバーの位置を変更し、カードビューではありません:D –

1

使用コーディネーターのレイアウトの代わりに、相対的なレイアウトとビューにlayout_behaviorプロパティを設定しますページャーから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> 
関連する問題