Java Code Examples for androidx.recyclerview.widget.RecyclerView#setItemAnimator()
The following examples show how to use
androidx.recyclerview.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: FragmentViewPager.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
private void initializeRecyclerView() { // Initialize Adapter and RecyclerView // Use of stableIds, I strongly suggest to implement 'item.hashCode()' FlexibleAdapter.useTag("ViewPagerAdapter"); mAdapter = new FlexibleAdapter<>(createList(50, 5), getActivity(), true); mAdapter.setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling); RecyclerView mRecyclerView = getView().findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(getActivity())); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setHasFixedSize(true); //Size of RV will not change // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange. mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!! FastScroller fastScroller = getView().findViewById(R.id.fast_scroller); mAdapter.setFastScroller(fastScroller); // Sticky Headers mAdapter.setDisplayHeadersAtStartUp(true) .setStickyHeaders(true); }
Example 2
Source File: GalleryNoteFragment.java From science-journal with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.gallery_note_fragment, null); RecyclerView gallery = rootView.findViewById(R.id.gallery); GridLayoutManager layoutManager = new GridLayoutManager( gallery.getContext(), gallery.getContext().getResources().getInteger(R.integer.gallery_column_count)); gallery.setLayoutManager(layoutManager); gallery.setItemAnimator(new DefaultItemAnimator()); gallery.setAdapter(galleryAdapter); addButton = rootView.findViewById(R.id.btn_add); requestPermission(); attachAddButton(addButton); actionController.attachAddButton(addButton); actionController.attachProgressBar(rootView.findViewById(R.id.recording_progress_bar)); setUpTitleBar(rootView, false, R.string.action_bar_gallery, R.drawable.ic_gallery); return rootView; }
Example 3
Source File: Simple1_Fragment.java From ui with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View myView = inflater.inflate(R.layout.simple1_fragment, container, false); String[] values = new String[]{"Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2"}; //setup the RecyclerView mRecyclerView = (RecyclerView) myView.findViewById(R.id.list); mRecyclerView.setLayoutManager(new LinearLayoutManager(myContext)); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); //setup the adapter, which is myAdapter, see the code. mAdapter = new Simple1_myAdapter(values, R.layout.simple1_rowlayout, myContext); //add the adapter to the recyclerview mRecyclerView.setAdapter(mAdapter); return myView; }
Example 4
Source File: PeopleActivity.java From mage-android with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_people); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new DividerItemDecoration(this, R.drawable.people_feed_divider)); recyclerView.setItemAnimator(new DefaultItemAnimator()); Collection<String> userIds = getIntent().getStringArrayListExtra(USER_REMOTE_IDS); try { people = UserHelper.getInstance(getApplicationContext()).read(userIds); } catch (UserException e) { Log.e(LOG_NAME, "Error read users for remoteIds: " + userIds.toString(), e); } adapter = new PeopleRecyclerAdapter(this, people); recyclerView.setAdapter(adapter); adapter.setOnPersonClickListener(this); }
Example 5
Source File: OptionsFragment.java From memorize with MIT License | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_options, container, false); prgLoading = (TSProgressBar) rootView.findViewById(R.id.options_progress); titleId = getResources().getStringArray(R.array.title); subtitleId = getResources().getStringArray(R.array.subtitle); userText = rootView.findViewById(R.id.user_name); userAvatar = rootView.findViewById(R.id.user_avatar); final RecyclerView mRecyclerView = rootView.findViewById(R.id.options_rv); mRecyclerView.setHasFixedSize(true); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(AppMain.getContext()); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setLayoutManager(mLayoutManager); RecyclerView.Adapter mAdapter = new OptionsAdapter(titleId, subtitleId, imageId); mRecyclerView.setAdapter(mAdapter); ImageLoader imageLoader = new ImageLoader(AppMain.getContext()); return rootView; }
Example 6
Source File: MainActivity.java From ui with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); List<String> values = Arrays.asList("Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2"); //setup the RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.list); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); //and default animator mRecyclerView.setItemAnimator(new DefaultItemAnimator()); //setup the adapter, which is myAdapter, see the code. mAdapter = new myAdapter(values, R.layout.my_row, this); //add the adapter to the recyclerview mRecyclerView.setAdapter(mAdapter); }
Example 7
Source File: ArmsUtils.java From MVPArms with Apache License 2.0 | 5 votes |
/** * 配置 RecyclerView * * @param recyclerView * @param layoutManager * @deprecated Use {@link #configRecyclerView(RecyclerView, RecyclerView.LayoutManager)} instead */ @Deprecated public static void configRecycleView(final RecyclerView recyclerView , RecyclerView.LayoutManager layoutManager) { recyclerView.setLayoutManager(layoutManager); //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能 recyclerView.setHasFixedSize(true); recyclerView.setItemAnimator(new DefaultItemAnimator()); }
Example 8
Source File: RecipientPreferenceActivity.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, savedInstanceState); recyclerView.setItemAnimator(null); recyclerView.setLayoutAnimation(null); return recyclerView; }
Example 9
Source File: ManageDevicesRecyclerFragment.java From science-journal with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_manage_devices, container, false); RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler); HeaderAdapter myHeader = new HeaderAdapter(R.layout.device_header, R.string.my_devices); HeaderAdapter availableHeader = new HeaderAdapter(R.layout.device_header, R.string.available_devices); if (savedInstanceState != null) { myDevices.onRestoreInstanceState(savedInstanceState.getBundle(KEY_MY_DEVICES)); availableDevices.onRestoreInstanceState(savedInstanceState.getBundle(KEY_AVAILABLE_DEVICES)); } CompositeRecyclerAdapter adapter = new CompositeRecyclerAdapter(myHeader, myDevices, availableHeader, availableDevices); adapter.setHasStableIds(true); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager( new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); // Don't animate on change: https://code.google.com/p/android/issues/detail?id=204277. SimpleItemAnimator animator = new DefaultItemAnimator(); animator.setSupportsChangeAnimations(false); recyclerView.setItemAnimator(animator); return view; }
Example 10
Source File: StorageSettingsFragment.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.simple_list, container, false); RecyclerView recyclerView = view.findViewById(R.id.items); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(layoutManager); StorageSettingsAdapter adapter = new StorageSettingsAdapter(getActivity()); recyclerView.setItemAnimator(null); recyclerView.setAdapter(adapter); return view; }
Example 11
Source File: PostFragment.java From Girls with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_fragment, null); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.activity_recycke_view); //设置adapter mRecyclerView.setAdapter(mGirlAdapter); //设置Item增加、移除动画 mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mRecyclerView.setHasFixedSize(false); //设置布局管理器 LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false); mRecyclerView.setLayoutManager(linearLayoutManager); mCircularProgressBar = (CircularProgressBar) rootView.findViewById(R.id.circular_progressbar); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout); swipeRefreshLayout.setColorSchemeColors( R.color.holo_red_light, R.color.holo_green_light, R.color.holo_blue_bright); //swipeRefreshLayout 设置下拉刷新事件 swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { getData(); //成功了 关闭刷新 swipeRefreshLayout.setRefreshing(false); } }); return rootView; }
Example 12
Source File: SelectDialog.java From AndroidProject with Apache License 2.0 | 5 votes |
public Builder(Context context) { super(context); setCustomView(R.layout.dialog_select); RecyclerView recyclerView = findViewById(R.id.rv_select_list); recyclerView.setItemAnimator(null); mAdapter = new SelectAdapter(getContext()); recyclerView.setAdapter(mAdapter); }
Example 13
Source File: ArmsUtils.java From MVPArms with Apache License 2.0 | 5 votes |
/** * 配置 RecyclerView * * @param recyclerView * @param layoutManager */ public static void configRecyclerView(final RecyclerView recyclerView , RecyclerView.LayoutManager layoutManager) { recyclerView.setLayoutManager(layoutManager); //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能 recyclerView.setHasFixedSize(true); recyclerView.setItemAnimator(new DefaultItemAnimator()); }
Example 14
Source File: MovieListFragment.java From androidMvvm with MIT License | 5 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view= inflater.inflate(R.layout.movie_list_fragment, container, false); recyclerView = (RecyclerView)view.findViewById(R.id.recycler_view); mAdapter = new MoviesAdapter(movieList); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext()); recyclerView.setLayoutManager(mLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(mAdapter); return view; }
Example 15
Source File: Utils.java From bottomsheets with Apache License 2.0 | 5 votes |
/** * Disables all the {@link RecyclerView} animations. */ public static void disableAnimations(@NonNull RecyclerView recyclerView) { Preconditions.nonNull(recyclerView); if(recyclerView.getItemAnimator() != null) { recyclerView.setItemAnimator(null); } }
Example 16
Source File: PhoneProfilesPrefsFragment.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
@Override public RecyclerView onCreateRecyclerView (LayoutInflater inflater, ViewGroup parent, Bundle state) { final RecyclerView view = super.onCreateRecyclerView(inflater, parent, state); view.setItemAnimator(null); view.setLayoutAnimation(null); return view; }
Example 17
Source File: ShadowsocksQuickSwitchActivity.java From Maying with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_quick_switch); profilesAdapter = new ProfilesAdapter(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(R.string.quick_switch); RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList); LinearLayoutManager lm = new LinearLayoutManager(this); profilesList.setLayoutManager(lm); profilesList.setItemAnimator(new DefaultItemAnimator()); profilesList.setAdapter(profilesAdapter); if (ShadowsocksApplication.app.profileId() >= 0) { int position = 0; List<Profile> profiles = profilesAdapter.profiles; for (int i = 0; i < profiles.size(); i++) { Profile profile = profiles.get(i); if (profile.id == ShadowsocksApplication.app.profileId()) { position = i + 1; break; } } lm.scrollToPosition(position); } if (Build.VERSION.SDK_INT >= 25) { ShortcutManager service = getSystemService(ShortcutManager.class); if (service != null) { service.reportShortcutUsed("switch"); } } }
Example 18
Source File: TaskerActivity.java From ShadowsocksRR with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_tasker); profilesAdapter = new ProfilesAdapter(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(R.string.app_name); toolbar.setNavigationIcon(R.drawable.ic_navigation_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); taskerOption = TaskerSettings.fromIntent(getIntent()); mSwitch = (Switch) findViewById(R.id.serviceSwitch); mSwitch.setChecked(taskerOption.switchOn); RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList); LinearLayoutManager lm = new LinearLayoutManager(this); profilesList.setLayoutManager(lm); profilesList.setItemAnimator(new DefaultItemAnimator()); profilesList.setAdapter(profilesAdapter); if (taskerOption.profileId >= 0) { int position = 0; List<Profile> profiles = profilesAdapter.profiles; for (int i = 0; i < profiles.size(); i++) { Profile profile = profiles.get(i); if (profile.id == taskerOption.profileId) { position = i + 1; break; } } lm.scrollToPosition(position); } }
Example 19
Source File: FilePickerActivity.java From FilePicker with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); configs = getIntent().getParcelableExtra(CONFIGS); if (configs == null) { configs = new Configurations.Builder().build(); } if (getIntent().hasExtra(DIR_ID)) dirId = getIntent().getLongExtra(DIR_ID, 0); if (useDocumentUi()) { MimeTypeMap mimeType = MimeTypeMap.getSingleton(); String[] suffixes = configs.getSuffixes(); String[] mime = new String[suffixes.length]; for (int i = 0; i < suffixes.length; i++) { mime[i] = mimeType.getMimeTypeFromExtension( suffixes[i].replace(".", "") ); } Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT) .setType("*/*") .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, configs.getMaxSelection() > 1) .putExtra(Intent.EXTRA_MIME_TYPES, mime); startActivityForResult(intent, REQUEST_DOCUMENT); return; } setContentView(R.layout.filepicker_gallery); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getIntent().hasExtra(DIR_TITLE)) title = getIntent().getStringExtra(DIR_TITLE); else if (configs.getTitle() != null) title = configs.getTitle(); if (title != null) title_res = R.string.selection_count_title; int spanCount; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { spanCount = configs.getLandscapeSpanCount(); } else { spanCount = configs.getPortraitSpanCount(); } int imageSize = configs.getImageSize(); if (imageSize <= 0) { Point point = new Point(); getWindowManager().getDefaultDisplay().getSize(point); imageSize = Math.min(point.x, point.y) / configs.getPortraitSpanCount(); } boolean isSingleChoice = configs.isSingleChoiceMode(); fileGalleryAdapter = new FileGalleryAdapter(this, imageSize, dirId == null && configs.isImageCaptureEnabled(), dirId == null && configs.isVideoCaptureEnabled()); fileGalleryAdapter.enableSelection(true); fileGalleryAdapter.enableSingleClickSelection(configs.isSingleClickSelection()); fileGalleryAdapter.setOnSelectionListener(this); fileGalleryAdapter.setSingleChoiceMode(isSingleChoice); fileGalleryAdapter.setMaxSelection(isSingleChoice ? 1 : configs.getMaxSelection()); fileGalleryAdapter.setSelectedItems(configs.getSelectedMediaFiles()); fileGalleryAdapter.setOnCameraClickListener(this); RecyclerView recyclerView = findViewById(R.id.file_gallery); recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount) { @Override public boolean isAutoMeasureEnabled() { return false; } }); recyclerView.setAdapter(fileGalleryAdapter); recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDimensionPixelSize(R.dimen.grid_spacing), spanCount)); recyclerView.setItemAnimator(null); recyclerView.setHasFixedSize(false); recyclerView.setItemViewCacheSize(20); if (requestPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_WRITE_PERMISSION)) { loadFiles(); } maxCount = configs.getMaxSelection(); if (maxCount > 0) { setTitle(getResources().getString(title_res, fileGalleryAdapter.getSelectedItemCount(), maxCount, title)); } }
Example 20
Source File: SimpleMenuPopupWindow.java From MaterialPreference with Apache License 2.0 | 4 votes |
@SuppressLint("InflateParams") public SimpleMenuPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setFocusable(true); setOutsideTouchable(false); TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SimpleMenuPopup, defStyleAttr, defStyleRes); elevation[POPUP_MENU] = (int) a.getDimension(R.styleable.SimpleMenuPopup_listElevation, 4f); elevation[DIALOG] = (int) a.getDimension(R.styleable.SimpleMenuPopup_dialogElevation, 48f); margin[POPUP_MENU][HORIZONTAL] = (int) a.getDimension(R.styleable.SimpleMenuPopup_listMarginHorizontal, 0); margin[POPUP_MENU][VERTICAL] = (int) a.getDimension(R.styleable.SimpleMenuPopup_listMarginVertical, 0); margin[DIALOG][HORIZONTAL] = (int) a.getDimension(R.styleable.SimpleMenuPopup_dialogMarginHorizontal, 0); margin[DIALOG][VERTICAL] = (int) a.getDimension(R.styleable.SimpleMenuPopup_dialogMarginVertical, 0); listPadding[POPUP_MENU][HORIZONTAL] = (int) a.getDimension(R.styleable.SimpleMenuPopup_listItemPadding, 0); listPadding[DIALOG][HORIZONTAL] = (int) a.getDimension(R.styleable.SimpleMenuPopup_dialogItemPadding, 0); dialogMaxWidth = (int) a.getDimension(R.styleable.SimpleMenuPopup_dialogMaxWidth, 0); unit = (int) a.getDimension(R.styleable.SimpleMenuPopup_unit, 0); maxUnits = a.getInteger(R.styleable.SimpleMenuPopup_maxUnits, 0); mList = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.simple_menu_list, null); mList.setFocusable(true); mList.setLayoutManager(new LinearLayoutManager(context)); mList.setItemAnimator(null); mList.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { getBackground().getOutline(outline); } }); mList.setClipToOutline(true); setContentView(mList); mAdapter = new SimpleMenuListAdapter(this); mList.setAdapter(mAdapter); a.recycle(); // TODO do not hardcode itemHeight = Math.round(context.getResources().getDisplayMetrics().density * 48); listPadding[POPUP_MENU][VERTICAL] = listPadding[DIALOG][VERTICAL] = Math.round(context.getResources().getDisplayMetrics().density * 8); }