Java Code Examples for android.support.v7.widget.RecyclerView#setItemAnimator()

The following examples show how to use android.support.v7.widget.RecyclerView#setItemAnimator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KowloonFragment.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_kowloon, container, false);

    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_kowloon);

    mAdapter = new ShopsAdapter(shopList, getActivity());
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL));
    recyclerView.setAdapter(mAdapter);
    mAdapter.notifyDataSetChanged();
    return view;
}
 
Example 2
Source File: PathLayoutManager.java    From PathLayoutManager with Apache License 2.0 6 votes vote down vote up
/**
     * 通过反射替换默认的Item动画 (解决在某些机型上的crash问题)
     */
    private void initItemAnimator() {
        try {
            Field field = RecyclerView.LayoutManager.class.getDeclaredField("mRecyclerView");
            field.setAccessible(true);
            RecyclerView recyclerView = (RecyclerView) field.get(this);
            if (recyclerView != null) {
                recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
                recyclerView.setHorizontalScrollBarEnabled(false);
                recyclerView.setVerticalScrollBarEnabled(false);
                if (recyclerView.getItemAnimator() != mItemAnimator) {
                    recyclerView.setItemAnimator(mItemAnimator);
                }
            }
//            recyclerView.setItemAnimator(null);
            mRecycler.setViewCacheSize(mCacheCount);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example 3
Source File: NotesFragment.java    From multi-copy with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root =  inflater.inflate(R.layout.fragment_notes, container, false);
    fabNewNote = (FloatingActionButton) root.findViewById(R.id.fabNewNote);
    recyclerView = (RecyclerView) root.findViewById(R.id.rvNotesList);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
    notesList = new ArrayList<>();
    if (notesFragment_LOG)
    Log.d(TAG, "onCreateView: " + notesList.toString());
    notesAdapter = new NotesAdapter(notesList,getContext());
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setAdapter(notesAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    fabNewNote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getActivity(),NewNoteActivity.class);
            startActivityForResult(i,Constants.NEW_NOTE_ACTIVTY_KEY);
        }
    });
    refreshData();
    implementREcyclerViewClickListener();
    return root;
}
 
Example 4
Source File: GroupPopularListFragment.java    From citrus with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    String categoryName = GroupHelper.CATEGORY_POPULAR;
    RealmResults<Group> groups = GroupRepository.findAllByCategoryName(mUIThreadRealm, categoryName);
    mGroupListAdapter = new GroupListAdapter(groups, this);

    RecyclerView recyclerView = findById(view, R.id.group_list_recycler_view);
    recyclerView.addItemDecoration(
            new DividerItemDecoration(Utils.getDrawableResource(getActivity(), R.drawable.line)));
    final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mGroupListAdapter);
}
 
Example 5
Source File: MenuFragment.java    From AdvancedMaterialDrawer with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.recycleview_layout, container, false);

    mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    createAdapter(mRecyclerView);

    return v;
}
 
Example 6
Source File: ListenerFragment.java    From AdvancedMaterialDrawer with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.recycleview_layout, container, false);

    mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    createAdapter(mRecyclerView);

    return v;
}
 
Example 7
Source File: LinearHVClassifyView.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected RecyclerView getSub(Context context, AttributeSet parentAttrs) {
    RecyclerView recyclerView = new RecyclerView(context);
    recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setChangeDuration(10);
    recyclerView.setItemAnimator(itemAnimator);
    return recyclerView;
}
 
Example 8
Source File: LinearVVClassifyView.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected RecyclerView getSub(Context context, AttributeSet parentAttrs) {
    RecyclerView recyclerView = new RecyclerView(context);
    recyclerView.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();
    itemAnimator.setChangeDuration(10);
    recyclerView.setItemAnimator(itemAnimator);
    return recyclerView;
}
 
Example 9
Source File: UiUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 配置recycleview
 *
 * @param recyclerView
 * @param layoutManager
 */
public static void configRecycleView(final RecyclerView recyclerView
        , RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
 
Example 10
Source File: Demo3Activity1.java    From RecyclerViewDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
//        recyclerview.setLayoutManager(new GridLayoutManager(this, 3));
//        recyclerview.setLayoutManager(new LinearLayoutManager(this,
//                LinearLayoutManager.VERTICAL, false));
        recyclerview.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));

        recyclerview.setItemAnimator(new DefaultItemAnimator()); //即使不设置,默认也是这个动画
        
        recyclerview.setAdapter(new Demo3Adapter(this));
    }
 
Example 11
Source File: ViewUtil.java    From RecyclerRenderers with Apache License 2.0 5 votes vote down vote up
public static void configRecyclerView(final Context context, RecyclerView recyclerView) {
  recyclerView.setHasFixedSize(true);
  recyclerView.setItemAnimator(new DefaultItemAnimator());
  GridLayoutManager layoutManager = new GridLayoutManager(context, 2);
  layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  recyclerView.addItemDecoration(new MarginDecoration(context));
  recyclerView.setLayoutManager(layoutManager);
  recyclerView.setAdapter(new RendererAdapter<Console>(generateConsoles(),
      new RendererBuilder(new Factory()), LayoutInflater.from(context)));
}
 
Example 12
Source File: RowTest.java    From ChipsLayoutManager with Apache License 2.0 5 votes vote down vote up
@Before
public final void setUp() throws Throwable {
    MockitoAnnotations.initMocks(this);
    activity = activityTestRule.getActivity();

    LayoutManagerFactory layoutManagerFactory = new LayoutManagerFactory() {
        @Override
        public RecyclerView.LayoutManager layoutManager(Context context) {
            return retrieveLayoutManager();
        }
    };

    RecyclerView rvTest = (RecyclerView) activityTestRule.getActivity().findViewById(R.id.rvTest);
    //disable all animations
    rvTest.setItemAnimator(null);

    //set items
    ChipsFacade chipsFacade = spy(new ChipsFacade());
    items = chipsFacade.getItems();
    when(chipsFacade.getItems()).thenReturn(items);
    TestActivity.setItemsFactory(chipsFacade);

    TestActivity.setLmFactory(layoutManagerFactory);

    recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));

    onSetUp();

    activity.runOnUiThread(() -> activity.initialize());
}
 
Example 13
Source File: FaceDetectRGBActivity.java    From FaceDetectCamera with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the UI and initiates the creation of a face detector.
 */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.activity_camera_viewer);

    mView = (SurfaceView) findViewById(R.id.surfaceview);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Now create the OverlayView:
    mFaceView = new FaceOverlayView(this);
    addContentView(mFaceView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    // Create and Start the OrientationListener:

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());


    handler = new Handler();
    faces = new FaceResult[MAX_FACE];
    faces_previous = new FaceResult[MAX_FACE];
    for (int i = 0; i < MAX_FACE; i++) {
        faces[i] = new FaceResult();
        faces_previous[i] = new FaceResult();
    }


    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Face Detect RGB");

    if (icicle != null)
        cameraId = icicle.getInt(BUNDLE_CAMERA_ID, 0);
}
 
Example 14
Source File: UiUtils.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 配置recycleview
 *
 * @param recyclerView
 * @param layoutManager
 */
public static void configRecycleView(final RecyclerView recyclerView
        , RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
 
Example 15
Source File: HeaderTypesFragment.java    From AdvancedMaterialDrawer with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.recycleview_layout, container, false);

    mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    createAdapter(mRecyclerView);
    return v;
}
 
Example 16
Source File: FangshiActivity.java    From MyBlogDemo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fangshi);
    recyclerView = (RecyclerView) findViewById(R.id.rv);
    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(manager);
    GridLayoutManager manager1 = new GridLayoutManager(this, 3);
    GridView gridView = new GridView(this);
    gridView.setNumColumns(3);

    recyclerView.setItemAnimator(new DefaultItemAnimator());
    adapter = new FangshiAdapter();
    recyclerView.setAdapter(adapter);
    //初始化一个TouchHelperCallback
    TouchHelperCallback callback = new TouchHelperCallback();
    //添加一个回调
    callback.setItemTouchCallBack(adapter);
    //初始化一个ItemTouchHelper
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    //关联相关的RecycleView
    itemTouchHelper.attachToRecyclerView(recyclerView);

    initData();

}
 
Example 17
Source File: UiUtils.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
/**
 * 配置recycleview
 *
 * @param recyclerView
 * @param layoutManager
 */
public static void configRecycleView(final RecyclerView recyclerView
        , RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
 
Example 18
Source File: FindMusicAty.java    From myapplication with Apache License 2.0 5 votes vote down vote up
private void initView() {
    titleBackIBtn = (ImageButton) findViewById(R.id.title_music_left_imv);
    mMusicPlayingImv = (ImageView) findViewById(R.id.item_music_playing_imv);
    mRecyclerView = (RecyclerView) findViewById(R.id.find_musics_recyclerview);
    mDatas = FileUtil.getLocalMusics(FindMusicAty.this.getContentResolver());

    mFindMusicAdapter = new FindMusicAdapter(FindMusicAty.this, mDatas);
    mLayoutManager = new LinearLayoutManager(FindMusicAty.this,
            LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setAdapter(mFindMusicAdapter);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());//默认动画
    mRecyclerView.setHasFixedSize(true);//效率最高

}
 
Example 19
Source File: CalendarFragment.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRoot = inflater.inflate(R.layout.fragment_calendar, container, false);

    // header views
    if ( mLandscape ) {

        mHeaderLayout = (LinearLayout) View.inflate(getActivity(), R.layout.calendar_toolbar_view, null);
        mToolbarTextView = (TextView) mHeaderLayout.findViewById(R.id.cal_header_text);
        mHeaderLayout.setOnClickListener(this);

        int position = 0;
        for ( position = 0; position < mainActivity.mViewPagerOrder.length; position++ )
            if ( mainActivity.mViewPagerOrder[position].equals(TAG) )
                break;

        if ( mainActivity.mViewPager.getCurrentItem() == position ) {
            LinearLayout toolbar = (LinearLayout) mainActivity.getSupportActionBar().getCustomView();
            toolbar.addView(mHeaderLayout);
            mAddedToolbarView = true;
        }

    } else {

        mDayHeaderView = (TextView) findViewById(R.id.cal_header_day);
        mDayOfWeekHeaderView = (TextView) findViewById(R.id.cal_header_day_of_week);
        mMonthYearHeaderView = (TextView) findViewById(R.id.cal_header_month_year);

        findViewById(R.id.cal_header_month_layout).setOnClickListener(this);
    }

    // main content view
    mAnimator = (AccessibleDateAnimator) findViewById(R.id.animator);

    mDayPickerView = new SimpleDayPickerView(getActivity(), this);
    mMonthPickerView = new MonthPickerView(getActivity(), this);
    mYearPickerView = new YearPickerView(getActivity(), this);

    mDayPickerView.setStickyDisplaySelectedDate(true);

    if ( !mLandscape ) {
        mDayPickerView.setFixedHeight(getResources().getDimensionPixelOffset(R.dimen.calendar_height));
    }

    int calColor = getResources().getColor(R.color.section_calendar);
    int r = Color.red(calColor);
    int g = Color.green(calColor);
    int b = Color.blue(calColor);

    mDayPickerView.setSelectedColor(Color.argb(0x59, r, g, b));
    mMonthPickerView.setSelectionColor(Color.argb(0x59, r, g, b));
    mYearPickerView.setSelectionColor(Color.argb(0x59, r, g, b));

    mYearPickerView.useRectangleSelector(true);

    mDayPickerView.setTodayColor(Color.BLACK);
    mDayPickerView.setDayPickerListener(this);

    mAnimator.addView(mDayPickerView);
    mAnimator.addView(mMonthPickerView);
    mAnimator.addView(mYearPickerView);

    mDayPickerView.setSelected(true);
    mMonthPickerView.setSelected(false);
    mYearPickerView.setSelected(false);

    mAnimator.setDateMillis(mCalendar.getTimeInMillis());

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(ANIMATION_DURATION);
    mAnimator.setInAnimation(animation);

    Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
    animation2.setDuration(ANIMATION_DURATION);
    mAnimator.setOutAnimation(animation2);

    // list view
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mLinearLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLinearLayoutManager);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addOnItemTouchListener(this);

    mAdapter = new EntriesRecyclerAdapter(mDisplayedEntries);
    mRecyclerView.setAdapter(mAdapter);

    mItemAnimator = new ScaleInOutItemAnimator(mRecyclerView);
    mRecyclerView.setItemAnimator(mItemAnimator);

    updateDisplay();
    updatePickers();

    return mRoot;
}
 
Example 20
Source File: DrawerFragment.java    From openshop.io-android with MIT License 4 votes vote down vote up
/**
 * Prepare drawer menu content views, adapters and listeners.
 *
 * @param view fragment base view.
 */
private void prepareDrawerRecycler(View view) {
    drawerRecycler = view.findViewById(R.id.drawer_recycler);
    drawerRecyclerAdapter = new DrawerRecyclerAdapter(getContext(), new DrawerRecyclerInterface() {
        @Override
        public void onCategorySelected(View v, DrawerItemCategory drawerItemCategory) {
            if (drawerItemCategory.getChildren() == null || drawerItemCategory.getChildren().isEmpty()) {
                if (drawerListener != null) {
                    if (drawerItemCategory.getId() == BANNERS_ID)
                        drawerListener.onDrawerBannersSelected();
                    else
                        drawerListener.onDrawerItemCategorySelected(drawerItemCategory);
                    closeDrawerMenu();
                } else {
                    Timber.e(new RuntimeException(), NULL_DRAWER_LISTENER_WTF);
                }
            } else
                animateSubListShow(drawerItemCategory);
        }

        @Override
        public void onPageSelected(View v, DrawerItemPage drawerItemPage) {
            if (drawerListener != null) {
                drawerListener.onDrawerItemPageSelected(drawerItemPage);
                closeDrawerMenu();
            } else {
                Timber.e(new RuntimeException(), NULL_DRAWER_LISTENER_WTF);
            }
        }

        @Override
        public void onHeaderSelected() {
            if (drawerListener != null) {
                drawerListener.onAccountSelected();
                closeDrawerMenu();
            } else {
                Timber.e(new RuntimeException(), NULL_DRAWER_LISTENER_WTF);
            }
        }
    });
    drawerRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
    drawerRecycler.setHasFixedSize(true);
    drawerRecycler.setAdapter(drawerRecyclerAdapter);

    RecyclerView drawerSubmenuRecycler = view.findViewById(R.id.drawer_submenu_recycler);
    drawerSubmenuRecyclerAdapter = new DrawerSubmenuRecyclerAdapter(new DrawerSubmenuRecyclerInterface() {
        @Override
        public void onSubCategorySelected(View v, DrawerItemCategory drawerItemCategory) {
            if (drawerListener != null) {
                drawerListener.onDrawerItemCategorySelected(drawerItemCategory);
                closeDrawerMenu();
            }
        }
    });
    drawerSubmenuRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
    drawerSubmenuRecycler.setItemAnimator(new DefaultItemAnimator());
    drawerSubmenuRecycler.setHasFixedSize(true);
    drawerSubmenuRecycler.setAdapter(drawerSubmenuRecyclerAdapter);
}