2015-08-17 2 views
0

В настоящее время мой RecyclerView отображается правильно, но не имеет разделителей между каждым набором данных/элементом.Как я могу добавить разделители для RecyclerView в android?

Это код, который я использую для моего RecyclerView, с расположением элементов, отображаемых в фрагменте кода ниже.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:id="@+id/relativeLayout"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    /> 

</RelativeLayout> 

Это код, который определяет, как элементы расположены.

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="0dp" 
     android:layout_weight="3" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/groupName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Group Name" 
      /> 

     <TextView 
      android:id="@+id/groupDate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Group Date" 
      /> 

     <TextView 
      android:id="@+id/groupLocation" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Group Location" 
      /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/className" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:gravity="right" 
      android:text="Class Name" 
      /> 
    </LinearLayout> 

</LinearLayout> 

Вот картина того, что приложение выглядит, с RecyclerView: http://imgur.com/WnJXkuV

+0

см 'android.support.v7 .widget.RecyclerView.ItemDecoration' – pskink

+0

Просто установите 'android: padding =" 10dp "' на ваш корневой макет –

+0

Я немного изменил свой пост. Какой из них вы имеете в виду, когда говорите, что корневой макет –

ответ

0

Вы можете добавить Сепаратор, как показано ниже

recyclerView.addItemDecoration 
      (new DividerItemDecoration(MyActivity.this, 
        DividerItemDecoration.VERTICAL_LIST)); 
Смежные вопросы