ScrollView嵌套ViewPager嵌套RecycleView item显示不全 2C

如图所示:图片说明
我在ScrollView里面嵌套了可以左右滑动的Viewpager,viewpager里面是上下滑动的
RecycleView,目前发现的问题是我给RecycleVIew设置的加载头显示不出来,最后一行也是显示不完全。感觉是滑动冲突的原因,但是网上没有系统的解决问题办法。请大家给点切实可行的解决办法吧
下面附上我的xml:
<?xml version="1.0" encoding="utf-8"?>
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rl_map_all"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--底部图层-->
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--底部图层-->

<!--右侧侧滑栏-->

<com.yinglan.scrolllayout.ScrollLayout
    android:id="@+id/scroll_down_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00550033"
    android:visibility="gone"
    app:allowHorizontalScroll="true"
    app:exitOffset="0dp"
    app:isSupportExit="true"
    app:maxOffset="300dp"
    app:minOffset="50dp"
    app:mode="open">
    <!--多条记录悬浮-->
    <com.yinglan.scrolllayout.content.ContentScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen1800"
                android:clickable="true"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="vertical">

                <com.example.administrator.im_demo.ui.view.navigationbar.indicators.MagicIndicator
                    android:id="@+id/magic_indicator"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dimen120"
                    android:background="@color/tab_title" />

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewpager_search_result"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>

            <TextView
                android:id="@+id/tv_next"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dimen110"
                android:background="@color/white"
                android:clickable="true"
                android:gravity="center"
                android:text="总共XX条记录"
                android:textColor="@color/white"
                android:textSize="@dimen/dimen32"
                android:visibility="gone" />
        </RelativeLayout>
    </com.yinglan.scrolllayout.content.ContentScrollView>
</com.yinglan.scrolllayout.ScrollLayout>

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_mapall"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:titleTextColor="@android:color/white"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    android:visibility="gone"/>


<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white">

    <com.wan7451.wanadapter.mylibrary.WanRecycleView
        android:id="@+id/recycleview_float_company"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


下面是几个引用的view:
/*
*

  • * sufly0001@gmail.com Modify the code to enhance the ease of use.
  • *
  • * Copyright (C) 2015 Ted xiong-wei@hotmail.com
  • * Licensed under the Apache License, Version 2.0 (the "License");
  • * you may not use this file except in compliance with the License.
  • * You may obtain a copy of the License at
  • *
  • * http://www.apache.org/licenses/LICENSE-2.0
  • *
  • * Unless required by applicable law or agreed to in writing, software
  • * distributed under the License is distributed on an "AS IS" BASIS,
  • * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • * See the License for the specific language governing permissions and
  • * limitations under the License. * * */

package com.yinglan.scrolllayout.content;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewParent;
import android.widget.ScrollView;

import com.yinglan.scrolllayout.ScrollLayout;

public class ContentScrollView extends ScrollView {

public interface OnScrollChangedListener {
    void onScrollChanged(int l, int t, int oldl, int oldt);
}

private OnScrollChangedListener listener;

public ContentScrollView(Context context) {
    super(context);
}

public ContentScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ContentScrollView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public void setOnScrollChangeListener(OnScrollChangedListener listener) {
    this.listener = listener;
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
    listener.onScrollChanged(l, t, oldl, oldt);
}

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    ViewParent parent = this.getParent();
    while (parent != null) {
        if (parent instanceof ScrollLayout) {
            ((ScrollLayout) parent).setAssociatedScrollView(this);
            break;
        }
        parent = parent.getParent();
    }
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    ViewParent parent = this.getParent();
    if (parent instanceof ScrollLayout) {
        if (((ScrollLayout) parent).getCurrentStatus() == ScrollLayout.Status.OPENED)
            return false;
    }
    return super.onTouchEvent(ev);
}

}


package com.wan7451.wanadapter.mylibrary;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

import com.handmark.pulltorefresh.library.PullToRefreshBase;

/**

  • Created by Hello on 2015/6/30.
    */
    public class WanRecycleView extends PullToRefreshBase {

    public WanRecycleView(Context context) {
    super(context);
    }

    public WanRecycleView(Context context, AttributeSet attrs) {
    super(context, attrs);
    }

    public WanRecycleView(Context context, Mode mode) {
    super(context, mode);
    }

    public WanRecycleView(Context context, Mode mode, AnimationStyle animStyle) {
    super(context, mode, animStyle);
    }

    @Override
    public Orientation getPullToRefreshScrollDirection() {
    return Orientation.VERTICAL;
    }

    @Override
    protected RecyclerView createRefreshableView(Context context, AttributeSet attrs) {
    RecyclerView view = new RecyclerView(context, attrs);
    view.setId(R.id.recycleView);
    return view;
    }

    @Override
    protected boolean isReadyForPullEnd() {
    int lastVisiblePosition = getRefreshableView().getChildAdapterPosition(getRefreshableView().getChildAt(getRefreshableView().getChildCount() -1));
    if (lastVisiblePosition >= getRefreshableView().getAdapter().getItemCount()-1) {
    return getRefreshableView().getChildAt(getRefreshableView().getChildCount() - 1).getBottom() <= getRefreshableView().getBottom();
    }
    return false;
    }

    @Override
    protected boolean isReadyForPullStart() {
    if (getRefreshableView().getChildCount() <= 0)
    return true;
    int firstVisiblePosition = getRefreshableView().getChildAdapterPosition(getRefreshableView().getChildAt(0));
    if (firstVisiblePosition == 0)
    return getRefreshableView().getChildAt(0).getTop() == getRefreshableView().getPaddingTop();
    else
    return false;
    }

}


3个回答

到网上下载FullyLinearLayoutManager,Recyclerview配置这个管理器就可以了,会整个填充

public class FullyLinearLayoutManager extends LinearLayoutManager {

private static final String TAG = FullyLinearLayoutManager.class.getSimpleName();

public FullyLinearLayoutManager(Context context) {
    super(context);
}

public FullyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
    super(context, orientation, reverseLayout);
}

private int[] mMeasuredDimension = new int[2];

@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 widthSize = View.MeasureSpec.getSize(widthSpec);
    final int heightSize = View.MeasureSpec.getSize(heightSpec);

    Log.i(TAG, "onMeasure called. \nwidthMode " + widthMode
            + " \nheightMode " + heightSpec
            + " \nwidthSize " + widthSize
            + " \nheightSize " + heightSize
            + " \ngetItemCount() " + getItemCount());

    int width = 0;
    int height = 0;
    for (int i = 0; i < getItemCount(); i++) {
        measureScrapChild(recycler, i,
                View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
                mMeasuredDimension);

        if (getOrientation() == HORIZONTAL) {
            width = width + mMeasuredDimension[0];
            if (i == 0) {
                height = mMeasuredDimension[1];
            }
        } else {
            height = height + mMeasuredDimension[1];
            if (i == 0) {
                width = mMeasuredDimension[0];
            }
        }
    }
    switch (widthMode) {
        case View.MeasureSpec.EXACTLY:
            width = widthSize;
        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(width, height);
}

private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                               int heightSpec, int[] measuredDimension) {
    try {
        View view = recycler.getViewForPosition(0);//fix 动态添加时报IndexOutOfBoundsException

        if (view != null) {
            RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();

            int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                    getPaddingLeft() + getPaddingRight(), p.width);

            int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                    getPaddingTop() + getPaddingBottom(), p.height);

            view.measure(childWidthSpec, childHeightSpec);
            measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
            measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
            recycler.recycleView(view);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问