2016-09-27 7 views
0

こんにちは私はそれぞれCardviewの間に分周器を表示したい単純なCardViewを持っています。問題は、除算器として使用する私のViewは、最後にCardViewに表示されることはありません。RecyclerViewです。ここに私の試みは次のとおりです。CardViewの下部に表示されないビューはありますか?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:fresco="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="100dp" 
    card_view:cardElevation="0dp" 
    android:id="@+id/cv_news_feed"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="16dp"> 

      ...Content... 


     </RelativeLayout> 

    </LinearLayout> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@color/material_color_grey_300" /> 

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

分周器は、何らかの理由で最後を除くすべてのCardViewのために現れ、これが発生している理由は、私はよく分かりません。どんな助けもありがとう、ありがとう!

EDIT:画像投稿: enter image description here

+0

スクリーンショットを共有してもよろしいですか? – raxelsson

+0

@raxelssonはスクリーンショットを投稿しました – user1871869

+0

仕切りは実際には 'FrameView'の上にレンダリングされます。これは' FrameLayout'を拡張し、重力を入れないためです。今あなたに役立ついくつかの答えがあります。 – raxelsson

答えて

0

CardViewがあなたの分周器の底にはないことを意味しFrameLayoutの延長でありますCardViewが上部にあります。

代わりにLinearLayoutに仕切板を配置してください。

+0

こんにちは、これはactaullyそれを修正しました。これをマークするのは好きな答えです。 – user1871869

+0

クールで幸せなコーディング! – raxelsson

0

すなわち、LinearLayoutにあなたの分周器を配置しようとすると:

1

あなたの項目から削除するには、次のビュー

<View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@color/material_color_grey_300" /> 

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(
       Utility.ItemDecorationConst); 
recyclerView.addItemDecoration(5); 

を次のようにItemDecorationを使用しようとDividerItemDecoration.java

public class DividerItemDecoration extends RecyclerView.ItemDecoration { 
    private int space; 

    public DividerItemDecoration(int space) { 
     this.space = space; 
    } 

    @Override 
    public void getItemOffsets(Rect outRect, View view, 
           RecyclerView parent, RecyclerView.State state) { 
     outRect.left = space; 
     outRect.right = space; 
     outRect.top = space; 
     outRect.bottom = space; 
    } 
} 
0

はにlayout_gravity属性を追加します。:

<View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_gravity="bottom" 
     android:background="@color/material_color_grey_300" /> 
-1

CardViewはので、あなたのデバイダがのLinearLayoutコンテンツの後ろになりますでframeLayout延びているためあなたが

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="16dp"> 

     ...Content... 


    </RelativeLayout> 

    <View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="@color/material_color_grey_300" /> 

</LinearLayout> 

次のように使用する必要があります。

+0

なぜ投票の相手が? – MinWan

0

あなたはこれがあなた

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     xmlns:fresco="http://schemas.android.com/tools" 
     android:id="@+id/cv_news_feed" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="100dp" 
     card_view:cardElevation="0dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="16dp"> 

       ...Content... 

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

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/cv_news_feed" 
     android:layout_marginTop="5dp" 
     android:background="@android:color/holo_red_dark" /> 
</RelativeLayout> 
0

はクラスDividerItemDecoration作成に役立つことを願って、このコードに試すことができます前に、addItemDecoration()メソッドを使用してアイテムの装飾を設定すると

import android.content.Context; 
import android.content.res.TypedArray; 
import android.graphics.Canvas; 
import android.graphics.Rect; 
import android.graphics.drawable.Drawable; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.view.View; 

/** 
* Created by Lincoln on 30/10/15. 
*/ 
public class DividerItemDecoration extends RecyclerView.ItemDecoration { 

    private static final int[] ATTRS = new int[]{ 
      android.R.attr.listDivider 
    }; 

    public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 

    public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 

    private Drawable mDivider; 

    private int mOrientation; 

    public DividerItemDecoration(Context context, int orientation) { 
     final TypedArray a = context.obtainStyledAttributes(ATTRS); 
     mDivider = a.getDrawable(0); 
     a.recycle(); 
     setOrientation(orientation); 
    } 

    public void setOrientation(int orientation) { 
     if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 
      throw new IllegalArgumentException("invalid orientation"); 
     } 
     mOrientation = orientation; 
    } 

    @Override 
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { 
     if (mOrientation == VERTICAL_LIST) { 
      drawVertical(c, parent); 
     } else { 
      drawHorizontal(c, parent); 
     } 
    } 

    public void drawVertical(Canvas c, RecyclerView parent) { 
     final int left = parent.getPaddingLeft(); 
     final int right = parent.getWidth() - parent.getPaddingRight(); 

     final int childCount = parent.getChildCount(); 
     for (int i = 0; i < childCount; i++) { 
      final View child = parent.getChildAt(i); 
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 
        .getLayoutParams(); 
      final int top = child.getBottom() + params.bottomMargin; 
      final int bottom = top + mDivider.getIntrinsicHeight(); 
      mDivider.setBounds(left, top, right, bottom); 
      mDivider.draw(c); 
     } 
    } 

    public void drawHorizontal(Canvas c, RecyclerView parent) { 
     final int top = parent.getPaddingTop(); 
     final int bottom = parent.getHeight() - parent.getPaddingBottom(); 

     final int childCount = parent.getChildCount(); 
     for (int i = 0; i < childCount; i++) { 
      final View child = parent.getChildAt(i); 
      final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 
        .getLayoutParams(); 
      final int left = child.getRight() + params.rightMargin; 
      final int right = left + mDivider.getIntrinsicHeight(); 
      mDivider.setBounds(left, top, right, bottom); 
      mDivider.draw(c); 
     } 
    } 

    @Override 
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 
     if (mOrientation == VERTICAL_LIST) { 
      outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 
     } else { 
      outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 
     } 
    } 
} 

をアダプターを設定します。

recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL)); 

// set the adapter 
recyclerView.setAdapter(mAdapter); 

N.B. cardviewレイアウトで使用しているビューを削除して、ディバイダを表示します。

関連する問題