How to change ListView elements for animation?

I want to implement a swapping ListView element with animations, for example, in an XE Currency Application

XE animation

from the list, when the user clicks on the GBP-British Pound, this line will rise and correspond to INR - Indian Rupee with animation and next INR - Indian Rupee will replace GBP-British Pound in place

I tried one animation in listview (using the title in listview), then it works fine, but the problem is that the title also scrolls up and down with listview, and I want the title (or any view) to be fixed at the top and bottom list can be scrolled

I tried one fix from above in Relative Layout and keep the listview under the top view, while the animation is being processed, but inside only the listview is not outside the listview

how can we implement this in android?

+5
source share
2 answers

Why reinvent the wheel? There are several well-documented and well-structured libraries for working with ListView . For example, ListViewAnimations is the best, IMO.

Functions

  • Appearance animations for items in ListViews , GridViews , and other AbsListViews
    • Built-in animations include Alpha , SwingRightIn , SwingLeftIn , SwingBottomIn , SwingRightIn and ScaleIn .
    • Other animations can be easily added.
    • StickyListHeaders supported, other implementations can be easily added.
  • Scroll to dismiss, scroll to avoid with contextual cancellation
  • Rearrange drag and drop This is what you need
  • Animation of adding elements
  • Smoothly expand your elements to show more content.

enter image description here

+2
source

I had a pretty similar problem a while ago. I needed a page where I can reinstall recordings (music tracks). So here is my implementation:

My AllTracksFragment, which allows you to reorder tracks

 public class AllTracksFragment extends SupportFragmentBase { DynamicListView allTracksListView; private ArrayList<Track> allTracksList = new ArrayList<>(); TracksListViewAdapter allTracksAdapter; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_all_tracks, container, false); setHasOptionsMenu(true); allTracksListView = (DynamicListView)rootView .findViewById(R.id.allTracksListView); Track track1 = new Track(); // Track is simple model class track1.trackName = "Winter\ Coming (Acoustic) 1"; track1.trackId = "47580057"; Track track2 = new Track(); track2.trackName = "Winter\ Coming (Acoustic) 2"; track2.trackId = "47580057"; Track track3 = new Track(); track3.trackName = "Winter\ Coming (Acoustic) 3"; track3.trackId = "47580057"; allTracksList.add(track1); allTracksList.add(track2); allTracksList.add(track3); allTracksAdapter = new TracksListViewAdapter(allTracksList, eventBus); allTracksListView.setTracksList(allTracksList); //SEE DynamicListView class allTracksListView.setAdapter(allTracksAdapter); allTracksListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); return rootView; } } 

And the AllTracksFragment layout:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <com.myapp.views.DynamicListView android:id="@+id/allTracksListView" android:layout_marginTop="12dp" android:scrollbars="none" android:divider="@null" android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout> 

TracksListViewAdapter (if necessary):

 public final class TracksListViewAdapter extends BaseListViewArrayAdapter<PlayTrackView, Track> { // extended version of simple BaseAdapter final int INVALID_ID = -1; public TracksListViewAdapter(final List<Track> tracks) { super(tracks == null ? new ArrayList<Track>(0) : tracks); if (tracks != null) { for (int i = 0; i < tracks.size(); ++i) { mIdMap.put(tracks.get(i), i); } } } public PlayTrackView createNewView(final Context context, final int position) { return new PlayTrackView(context); // PlayTrackView - is an extension of FrameLayout } HashMap<Track, Integer> mIdMap = new HashMap<>(); @Override public long getItemId(int position) { if (position < 0 || position >= mIdMap.size()) { return INVALID_ID; } Track item = (Track) getItem(position); return mIdMap.get(item); } @Override public boolean hasStableIds() { return android.os.Build.VERSION.SDK_INT < 20; } } 

PlayTrackView .java

 public class PlayTrackView extends FrameLayout implements IItemDisplayer<Track> { public PlayTrackView(Context context) { super(context); LayoutInflater.from(context).inflate(R.layout.play_track_view, this); } public PlayTrackView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.play_track_view, this); } public PlayTrackView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); LayoutInflater.from(context).inflate(R.layout.play_track_view, this); } @Override public void displayItem(Track track) { } } 

Track .java

 public class Track { public String trackId; public String trackName; } 

Interface IItemDisplayer

 public interface IItemDisplayer<TItem> { public void displayItem(TItem item); } 

BaseListViewAdapter

BaseListViewArrayAdapter

+1
source

Source: https://habr.com/ru/post/1204468/


All Articles