水平滑动
设置fruit_Item.xml中的排列方式为垂直,宽度为100dp,如果宽度设置为match_parent的话,子项将会占满了整个屏幕。
再讲TextView中的属性设置为
android:layout_marginTop=”10dp”//表示两者之间的距离。并且图片和文字的属性都设置为 android:layout_gravity=”center_horizontal”。
在onCreat()中的recyclerview.setLayoutManager上添加以下这一条代码
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);//里面的参数表示让布局横行排列。
瀑布流布局
设置布局的宽度为match_parent,和设置 android:layout_margin=”5dp”表示布局与布局之间的距离为5dp
再设置TextView的方向
在onCreat()
中设置
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL);//三行,纵向排列
recyclerView.setLayoutManager(layoutManager);//将其显示