2014-10-11 50 views
5

我想要實現從列表交換ListView項與動畫像XE貨幣應用如何交換帶有動畫的ListView項目?

XE animation

當英鎊,英鎊用戶輕敲該行會上升側,適合於INR - 與印度盧比動畫和行INR - 印度盧比將取代英鎊 - 英鎊的地方

我已經在列表視圖中嘗試過一個動畫(在列表視圖中使用的標題),那麼它是工作完美的,但問題是,標題也滾動了並與列表視圖下來,我希望固定在頂部和下面的列表視圖(或任何視圖)可以滾動列表

我曾嘗試一個修正觀點在相對佈局上面,並保持在那個時候動畫頂視圖下方的列表視圖中工作,但只裏面沒有列表視圖列表視圖外的

我們如何可以實現在android系統?

+0

看到這個項目:https://github.com/terlici/DragNDropList – 2015-02-24 11:36:49

+0

@ y.feizi:這是庫項目,給我鏈接演示使用這個庫 – Jayesh 2015-02-24 11:46:59

回答

1

前段時間我的問題很相似。我需要一個頁面,在那裏我可以重新安排條目(音樂歌曲曲目)。因此,這裏是我的實現:

我AllTracksFragment,允許重新排序跟蹤

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\'s Coming (Acoustic) 1"; 
     track1.trackId = "47580057"; 

     Track track2 = new Track(); 
     track2.trackName = "Winter\'s Coming (Acoustic) 2"; 
     track2.trackId = "47580057"; 

     Track track3 = new Track(); 
     track3.trackName = "Winter\'s 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; 
    } 
} 

而且AllTracksFragment佈局:

<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> 

TracksLi stViewAdapter(如果需要):

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) { 

    } 
} 

軌道的.java

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

IItemDisplayer接口

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

BaseListViewAdapter

+0

什麼是@Inject這裏?你使用哪個庫?它是註釋嗎? – Jayesh 2015-02-24 12:12:13

+0

@InjectView它來自黃油刀。它只意味着DynamicListView allTracksListView =(DynamicListView)getFragmentView()。findViewById(R.id.allTracksListView); (更短,更容易閱讀的形式+更有效的一個,據我所知)(更新答案,以避免這種注入) – 2015-02-24 12:15:00

+0

好吧,但無法找到PlayTrackView,Track,BaseListViewArrayAdapter – Jayesh 2015-02-24 12:22:03

2

爲什麼另起爐竈?有一些處理ListView的文檔和結構良好的庫。例如ListViewAnimations是最好的一個,IMO。

特點

  • 物品外觀的動畫在ListViewsGridViews,其他AbsListViews
    • 內置動畫包括AlphaSwingRightInSwingLeftInSwingBottomInSwingRightInScaleIn
    • 可以輕鬆添加其他動畫
    • 支持StickyListHeaders,可以輕鬆添加其他實現。
  • 刷卡到辭退,橫掃到辭退與上下文撤消
  • 拖動和拖放重新排序This is what you need
  • 動畫除了項目
  • 順利拓展您的項目揭示更多內容

enter image description here

+0

推薦的[library](https:// github。 com/nhaarman/ListViewAnimations)已棄用。 – 2018-01-16 12:11:24