如何在Recyclerview中分隔项目?

时间:2016-01-26 03:26:13

标签: java android material-design

嘿我如何在recyclerview中分隔项目,我目前在java中使用数组来提供图像和对象的名称,但是,它不会让我使用填充来填充列表中的项目? ?

<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="com.athena.athenafront.NavigationFragment"
                xmlns:app="http://schemas.android.com/apk/res-auto"

                android:background="@android:color/white">
<!-- TODO: Update blank fragment layout -->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/primaryColor"
            />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/drawer_recyclerview"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:choiceMode="singleChoice"
        android:dividerHeight="0dp"
        android:background="#ffff"
        android:layout_height="400dp">
    </android.support.v7.widget.RecyclerView>

这是我的java

public static List<AthenaPanel> getData() {
    //created an object for ur Drawer recyclerview array
    List<AthenaPanel> data= new ArrayList<>();
    //this is where you would add all your icons for the drawer list
    //arrays of icons
    int[] icons={R.mipmap.ic_launcher};
    String[] titles = {"Explore","Myprofile","MyStatus","Calendar","Setting","Send FeedBack"};
    //this is our for loop to cycle through the icons and the titles
    for(int i=0;i<5;i++){
        AthenaPanel current=new AthenaPanel();
        //i%().length allows ups to loop over the array any number of times we want to
        current.iconId=icons[i%icons.length];
        current.title=titles[i%titles.length];
        data.add(current);
    }
    return data;
}

1 个答案:

答案 0 :(得分:0)

要在RV上添加空间,请执行以下操作:

public static boolean isFlashLightEnabled() { boolean Enabled = false; if (camera == null) { camera = Camera.open(); camera.startPreview(); Camera.Parameters parameter = camera.getParameters(); Log.d("LOG", (parameter.getFlashMode().equalsIgnoreCase("torch")) ? "Torch" : "No Torch"); Enabled = parameter.getFlashMode().equalsIgnoreCase("torch"); } if (camera != null) { Camera.Parameters parameter = camera.getParameters(); Log.d("LOG", (parameter.getFlashMode().equalsIgnoreCase("torch")) ? "Torch" : "No Torch"); Enabled = parameter.getFlashMode().equalsIgnoreCase("torch"); camera.stopPreview(); camera.release(); camera = null; } return Enabled; } xml上,使用此:RecyclerView或您喜欢的任何其他值。与android:padding="8dp"一起。

E.g:

android:clipToPadding="false"

有关here的更多信息。

要在RV项目上添加空间,您必须编辑项目行的XML文件并在那里添加边距/填充。

编辑:也许this question是相关的。