2016-07-07 13 views
0

問題:
リサイクルビューでcardviewを使用すると、上部と下部のデフォルトの余白が取られます。 Issue Image Linkアンドロイドカードビューのマージンの下端がデフォルトよりも大きい

両方で同じマージンを維持する方法は?

は、ここではカードレイアウトの私のxmlあなたrowitemで

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="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="@color/cardcolor" 

    android:orientation="vertical" 
    > 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     card_view:cardElevation="0dp" 
     card_view:cardPreventCornerOverlap="false" 
     android:foreground="?android:attr/selectableItemBackground" 
     card_view:cardCornerRadius="2dp" 
     card_view:contentPadding="10dp" 
     card_view:cardUseCompatPadding="false" > 

     ..//body  

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


</LinearLayout> 

マイリサイクラービュー

<RelativeLayout 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=".HomePageActivity"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/my_recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" 
     layout_marginBottom="5dp" 
     android:background="@color/white"/> 

</RelativeLayout> 
+0

@PiyushGupta私は最近、このサイトを参照して追加しました。取り外した後もまだ効果がありません。 –

+0

ちょうどあなたのRecyclerListViewの5dpのパディングを与えると、完全なアイテムが10dpの同じパディングを持つことがわかります –

+0

また、cardviewの余白も変更されましたか? – Drv

答えて

0

は、以下のように行います:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="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="@color/cardcolor" 
android:marginTop="2.5dp" 
android:marginBottom="2.5dp" 
android:layout_marginRight="5dp" 
android:layout_marginLeft="5dp" 
android:orientation="vertical"> 

<android.support.v7.widget.CardView 
    android:id="@+id/card_view" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    card_view:cardElevation="0dp" 
    card_view:cardPreventCornerOverlap="false" 
    android:foreground="?android:attr/selectableItemBackground" 
    card_view:cardCornerRadius="2dp" 
    card_view:contentPadding="10dp" 
    card_view:cardUseCompatPadding="false" > 

    ..//body  

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


</LinearLayout> 

と親のレイアウトにあなたのrecyclerviewに余裕を与えます:

<RelativeLayout 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" 
layout_marginTop="2.5dp" 
layout_marginBottom="2.5dp" 
tools:context=".HomePageActivity"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/my_recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical" 
    android:background="@color/white"/> 

    </RelativeLayout> 
+0

not working :(http://imgur.com/eZblHenを参照してください) –

+0

申し訳ありませんが、まだレイアウトはそのままです。私はリサイクラビューでアンドロイドの余白を追加しました:paddingTop = "5dp" android:paddingBottom = "0dp " –

+0

marginBottomを除いて、recyclerviewとその親レイアウトに他の余白やパディングを追加しないことを願っていますか? – Drv

関連する問題