如题,就把项目中常见的这几个冲突总结下吧,记性不太好,还是写下来好了。
ScrollView嵌套RecyclerView
滑动不流畅冲突:在RecyclerView属性中加入
android:nestedScrollingEnabled="false"
使recyclerview的滑动跟随scrollveiw
scrollview中组件不能充满:
Android:fillViewport="true"
允许Scrollview中的组件填充它
RecyclerView显示在布局顶部:
mRecyclerTest.setFocusable(false);//失去焦点
ScrollView嵌套GridView、ListView
只显示一行:自定义一个gridview重新绘制item高度
public class MyGridView extends GridView {
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
GridView顶部显示问题:
在GridView的父View中加入属性
android:focusable="true"
android:focusableInTouchMode="true"
ScrollView嵌套ViewPager
viewpager不显示:重新定义一个ViewPager
public class ScrollViewPager extends ViewPager{
public ScrollViewPager(Context context) {
super(context);
}
public ScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height)height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
CollapsingToolbarLayout和GridView一起使用,滑动gridview无折叠效果
ViewCompat.setNestedScrollingEnabled(mGridView,true);