package app.tdj.com.recycleview.activity;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public class FullLinearLayout extends LinearLayoutManager {
private int[] mMeasuredDimension = new int[2];
int dividerHeight = 1;
@SuppressWarnings("UnusedDeclaration")
public FullLinearLayout(Context context, int dividerHeight) {
super(context);
this.dividerHeight = dividerHeight;
}
@SuppressWarnings("UnusedDeclaration")
public FullLinearLayout(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
final int widthMode = View.MeasureSpec.getMode(widthSpec);
final int heightMode = View.MeasureSpec.getMode(heightSpec);
final int heightSize = View.MeasureSpec.getSize(heightSpec);
int width = 0;
int height = 0;
for (int i = 0; i < getItemCount(); i++) {
try {
measureScrapChild(recycler, i, widthSpec, View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED), mMeasuredDimension);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
if (getOrientation() == HORIZONTAL) {
width = width + mMeasuredDimension[0];
if (i == 0) {
height = mMeasuredDimension[1];
}
} else {
height = height + mMeasuredDimension[1] + dividerHeight;
if (i == 0) {
width = mMeasuredDimension[0];
}
}
}
switch (widthMode) {
case View.MeasureSpec.EXACTLY:
case View.MeasureSpec.AT_MOST:
case View.MeasureSpec.UNSPECIFIED:
}
switch (heightMode) {
case View.MeasureSpec.EXACTLY:
height = heightSize;
case View.MeasureSpec.AT_MOST:
case View.MeasureSpec.UNSPECIFIED:
}
setMeasuredDimension(widthSpec, height);
}
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec, int heightSpec, int[] measuredDimension) {
View view = recycler.getViewForPosition(position);
if (view != null) {
RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec, getPaddingTop() + getPaddingBottom(), p.height);
view.measure(widthSpec, childHeightSpec);
measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
recycler.recycleView(view);
}
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
super.onLayoutChildren(recycler, state);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ScrollView嵌套RecycleView解决高度不适配
共36个文件
xml:10个
java:7个
png:5个
5星 · 超过95%的资源 需积分: 0 441 下载量 120 浏览量
2016-04-16
16:15:09
上传
评论 1
收藏 95KB RAR 举报
温馨提示
ScrollView嵌套RecycleView,会出现RecycleView显示不出来的问题,或者滑动不顺畅的问题,这里可以帮你解决。
资源推荐
资源详情
资源评论
收起资源包目录
RecycleViewForScrollView.rar (36个子文件)
RecycleViewForScrollView
gradlew.bat 2KB
gradlew 5KB
gradle.properties 872B
RecycleView.iml 942B
app
proguard-rules.pro 696B
src
test
java
app
tdj
com
recycleview
ExampleUnitTest.java 330B
androidTest
java
app
tdj
com
recycleview
ApplicationTest.java 366B
main
res
menu
menu_main.xml 408B
mipmap-xxxhdpi
ic_launcher.png 10KB
drawable
mipmap-hdpi
ic_launcher.png 3KB
values
colors.xml 258B
strings.xml 131B
styles.xml 728B
dimens.xml 259B
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
layout
notes_item.xml 1KB
activity_main.xml 2KB
values-v21
styles.xml 337B
values-w820dp
dimens.xml 364B
java
app
tdj
com
recycleview
data
adapter
RecycleViewDivider.java 2KB
NoteAdapter.java 2KB
entity
Note.java 368B
activity
FullLinearLayout.java 3KB
MainActivity.java 2KB
AndroidManifest.xml 809B
app.iml 9KB
.gitignore 8B
build.gradle 757B
libs
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 237B
.gitignore 105B
local.properties 463B
settings.gradle 16B
build.gradle 521B
共 36 条
- 1
资源评论
- zw4692018-04-03有用的,解决了问题
- zhang1369382016-08-23滑动是个大问题,在Recycleview里面会卡顿
- waiwaaa2018-01-09可以解决自动高度问题
- syp4765964972018-10-25不错不错不错
bake_
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功