【问题标题】:How do I space out items in a recyclerview?如何在回收站视图中分隔项目?
【发布时间】:2016-01-26 03:26:12
【问题描述】:

嘿,我如何在 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;
}

【问题讨论】:

    标签: java android material-design


    【解决方案1】:

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

    在您的 RecyclerView xml 中,使用:android:padding="8dp" 或您喜欢的任何其他值。还有android:clipToPadding="false"。

    例如:

    <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:clipToPadding="false"
        android:padding="8dp">
    </android.support.v7.widget.RecyclerView>
    

    关于here的更多信息。


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

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

    【讨论】:

      猜你喜欢
      • 2017-09-17
      • 2020-11-02
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2016-10-03
      相关资源
      最近更新 更多