Recylerview内的Android ViewPageIndicator未显示

时间:2016-02-08 06:52:30

标签: android android-recyclerview android-cardview viewpagerindicator

我在ViewPageIndicator项内添加了recylcerview,这是recyclerviewlayout

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="@color/background"
    card_view:cardCornerRadius="0dp"
    card_view:cardElevation="0dp"
    android:fillViewport="true">

    <LinearLayout
        android:id="@+id/main_container"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/view_pager"
            android:layout_width="match_parent"
            android:layout_height="100dp" />

        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/pager_indicator"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" />

    </LinearLayout>

</android.support.v7.widget.CardView>
ViewPageIndicator时{p> scrolling down未显示,但当我scrolling up显示某些项目时,请提供帮助。

1 个答案:

答案 0 :(得分:0)

问题发生在viewpager适配器上,我同时使用FragmentStatePagerAdapterFragmentPagerAdapter但没有成功。所以最后将适配器更改为PagerAdapter,并在instantiateItem中的PagerAdapter中实现我的片段视图

public class FeedImageAdapter extends PagerAdapter {

    private ArrayList<FeedContentGroup> feedContentGroups;

    private Context mContext;

    private LayoutInflater layoutInflater;

    public FeedImageAdapter(Context context, ArrayList<FeedContentGroup> feedContentGroups) {
        this.mContext = context;
        this.feedContentGroups = feedContentGroups;
        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public Object instantiateItem(ViewGroup collection, int position) {
        View v = layoutInflater.inflate(R.layout.feed_image_view, null);

        ImageView image1 = (ImageView) v.findViewById(R.id.image1);

        FeedContentGroup mFeedContentGroup = feedContentGroups.get(position);

        if (mFeedContentGroup.getContent1() != null && mFeedContentGroup.getContent1().getThumbnail_file_path() != null) {
            Glide.with(mContext).load(mFeedContentGroup.getContent1().getThumbnail_file_path()).into(image1);
        } else {
            image1.setVisibility(View.GONE);
        }

        ((ViewPager) collection).addView(v, 0);
        return v;
    }

    @Override
    public void destroyItem(View collection, int position, Object view) {
        ((ViewPager) collection).removeView((View) view);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public int getCount() {
        return feedContentGroups.size();
    }
}