先上图:第一次进入时,布局是正常的。
当向下滑动之后,又向上滑动时,布局大小发生变化。如图:
代码如下:
private void initRecyclerView() {
mAdapter = new SchoolmateAdapter(R.layout.item_topic_details, mData, this);
mAdapter.setOnLoadMoreListener(this, mRecyclerView);
mAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
// mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mAdapter);
mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
Toaster.showShort("当前位置" + position);
SchoolmateBean.ContentBean bean = (SchoolmateBean.ContentBean) adapter.getItem(position);
Intent intent = new Intent(SchoolmateActivity.this, SchoolmateDetailsActivity.class);
intent.putExtra(TEACHING_SHOWID, bean.getTeachingShowId());
startActivity(intent);
}
});
//SchoolmateAdapter中主要代码
@Override
protected void convert(BaseViewHolder helper, final SchoolmateBean.ContentBean item) {
ImageLoader.getInstance().loadCircleImage(mContext, item.getPhoto(), (ImageView) helper.getView(R.id.iv_avatar));
helper.setText(R.id.tv_name, item.getPersonName())
.setText(R.id.tv_devices, "")
.setText(R.id.tv_time, "")
.setText(R.id.tv_content, item.getText());
//显示图片,最多6张
if (item != null && item.getPhotopath() != null && item.getPhotopath().size() > 0) {
RecyclerView recyclerView = helper.getView(R.id.recycler_view_img);
initImageRecyclerView(recyclerView, item.getPhotopath(), mContext);
}
}
/**
* 初始化图片
* 图片最多6张
*
* @param recyclerView
* @param images
*/
private void initImageRecyclerView(RecyclerView recyclerView, List<String> images, Context context) {
ImageAdapter imageAdapter = new ImageAdapter(R.layout.item_student_style_image, images, context);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(imageAdapter);
imageAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
Toaster.showShort("position=" + position);
}
});
}
//ImageAdapter主要代码
@Override
protected void convert(BaseViewHolder helper, String item) {
ImageView imageView = helper.getView(R.id.iv_img);
ImageLoader.getInstance().loadRoundImage(mContext, item, DisplayUtils.dp2px(5), imageView);
//为图片添加点击事件
helper.addOnClickListener(R.id.iv_img);
}
//SchoolmateAdapter的Item布局
<?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_marginBottom="@dimen/dp_10"
android:background="@drawable/selector_recycler_view_bg"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_avatar"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_marginLeft="@dimen/dp_16"
android:layout_marginStart="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_16"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/gys" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_24"
android:layout_marginStart="@dimen/dp_24"
android:text="张琳琳 · 妈妈"
android:textColor="@color/black_333_color"
android:textSize="@dimen/text_size_18"
app:layout_constraintLeft_toRightOf="@+id/iv_avatar"
app:layout_constraintTop_toTopOf="@+id/iv_avatar" />
<TextView
android:id="@+id/tv_devices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="来自iphone 7"
android:textColor="@color/black_999_color"
android:textSize="@dimen/text_size_14"
app:layout_constraintBottom_toBottomOf="@+id/iv_avatar"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintTop_toBottomOf="@+id/tv_name" />
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/dp_16"
android:layout_marginRight="@dimen/dp_16"
android:text="五个小时之前"
android:textColor="@color/black_999_color"
android:textSize="@dimen/text_size_14"
app:layout_constraintBottom_toBottomOf="@+id/tv_devices"
app:layout_constraintRight_toRightOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/dp_80"
tools:layout_editor_absoluteX="@dimen/dp_80"
tools:layout_editor_absoluteY="0dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_img"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="@dimen/dp_16"
android:layout_marginTop="0dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_devices" />
<TextView
android:id="@+id/tv_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="@dimen/dp_16"
android:text="小星星不会了,动手做一个小星星还是可以的。"
android:textColor="@color/black_333_color"
android:textSize="@dimen/text_size_16"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toRightOf="@+id/recycler_view_img"
app:layout_constraintTop_toBottomOf="@+id/recycler_view_img" />
<ImageView
android:id="@+id/view4"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="@dimen/dp_16"
android:background="#000000"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintRight_toRightOf="@+id/tv_content"
app:layout_constraintTop_toBottomOf="@+id/tv_content" />
<com.kuojie.family_xiaoyinxing.widget.MyClickTools
android:id="@+id/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
app:layout_constraintRight_toRightOf="@+id/view4"
app:layout_constraintTop_toBottomOf="@+id/view4" />
<TextView
android:id="@+id/tv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_8"
android:layout_marginLeft="@dimen/dp_24"
android:layout_marginTop="@dimen/dp_8"
android:text="删除"
android:textColor="@color/black_666_color"
android:textSize="@dimen/text_size_16"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/tools"
app:layout_constraintLeft_toLeftOf="@+id/guideline3"
app:layout_constraintTop_toTopOf="@+id/tools" />
</android.support.constraint.ConstraintLayout>
//ImageAdapter的Item布局代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_recycler_view_bg"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_img"
android:layout_width="@dimen/dp_60"
android:layout_height="@dimen/dp_60"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/dp_10"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10"
android:scaleType="centerCrop"
android:src="@drawable/gys" />
</LinearLayout>