Fragment set recyclerView columns number:
sortRecyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager rvLayoutManager = new GridLayoutManager(getActivity(), 2);
sortRecyclerView.setLayoutManager(rvLayoutManager);
这里布局内容recyclerView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/sortRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
此处在recyclerView中的项目布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@color/place_holder_color">
<ImageView
android:id="@+id/imageViewPhoto"
android:layout_width="@dimen/preview_image_height"
android:layout_height="@dimen/preview_image_height"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
结果如下:
我需要接下来:
答案 0 :(得分:0)
你可以设置这样的东西: - 对于1&#39; st ImageView:
android:paddingLeft="10dp"
android:paddingRight="5dp"
用于2&#image ImageView:
机器人:paddingLeft =&#34; 5DP&#34;
机器人:paddingRight =&#34; 10dp&#34;
答案 1 :(得分:0)
添加到左侧的那个:
android:marginRight="5dp"
android:marginLeft="20dp"
添加到右边的那个:
android:marginLeft="5dp"
android:marginRight="20dp"