如何在页面滚动中应用FlipBoard Like Animation?

时间:2016-11-15 10:36:39

标签: android android-recyclerview

我想创建一个可以翻转我的页面的应用程序in this Style. 我该怎么做?我使用了Recycler View,但列表是可滚动的形式。我想将这个可滚动到像上面的库一样的动画。

我的主要活动

public class MainActivity extends AppCompatActivity {

@Bind(R.id.my_recycler_view)
RecyclerView mRecyclerView;
@Bind(R.id.fast_scroller)
RecyclerViewFastScroller fastScroller;

private List<String> mDataArray;
private List<AlphabetItem> mAlphabetItems;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    initialiseData();
    initialiseUI();
}

protected void initialiseData() {
    //Recycler view data
    mDataArray = DataHelper.getAlphabetData();

    //Alphabet fast scroller data
    mAlphabetItems = new ArrayList<>();
    List<String> strAlphabets = new ArrayList<>();
    for (int i = 0; i < mDataArray.size(); i++) {
        String name = mDataArray.get(i);
        if (name == null || name.trim().isEmpty())
            continue;

        String word = name.substring(0, 1);
        if (!strAlphabets.contains(word)) {
            strAlphabets.add(word);
            mAlphabetItems.add(new AlphabetItem(i, word, false));
        }
    }
}

protected void initialiseUI() {
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setAdapter(new RecyclerViewAdapter(mDataArray));

    fastScroller.setRecyclerView(mRecyclerView);
    fastScroller.setUpAlphabet(mAlphabetItems);
}

我的适配器

    public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>
    implements RecyclerViewFastScroller.BubbleTextGetter {

    private List<String> mDataArray;

    public RecyclerViewAdapter(List<String> dataset) {
        mDataArray = dataset;
    }

    @Override
    public int getItemCount() {
        if (mDataArray == null)
            return 0;
        return mDataArray.size();
    }

    @Override
    public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_view_layout, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.mTextView.setText(mDataArray.get(position));
    }

    @Override
    public String getTextToShowInBubble(int pos) {
        if (pos < 0 || pos >= mDataArray.size())
            return null;

        String name = mDataArray.get(pos);
        if (name == null || name.length() < 1)
            return null;

        return mDataArray.get(pos).substring(0, 1);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_alphabet)
        TextView mTextView;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}

0 个答案:

没有答案