这默认打开的状态:上图
这是点击切换按钮后的状态,可以发现 recyclerView 是完全倒置 数据是从下到上排序依次增大,而listView 倒置之后是也是从下往上依次减少排序,自己可以根据不同的需求运用不同的功能,点击固定按钮RecyclerView 不可滑动,ListView 并没有做出处理,自己可以去尝试一下,由于不能做出动画效果给大家只能一张张图片往上贴,还望包涵,谢谢大家!
代码:贴出一部分,其余是适配器
public class RecyclerListViewActivity extends AppCompatActivity { private TextView mChangTextView; private TextView mOtherTextView; private RecyclerView mRecyclerView; private MyRecyclerAdapter mRecyclerAdapter; private ListView mListView; private boolean mReverseLayout = false; private boolean mScaledTouchSlop = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recycler_list_view); initView(); initListView(); initRecylerView(); } private void initView() { mChangTextView = (TextView) findViewById(R.id.changTextView); mChangTextView.setOnClickListener(mChangListener); mOtherTextView = (TextView) findViewById(R.id.otherTextView); mOtherTextView.setOnClickListener(mOtherListener); } private void initListView() { mListView = (ListView) findViewById(R.id.listItem); MyListViewAdapter listAdapter = new MyListViewAdapter(); mListView.setAdapter(listAdapter); mListView.setStackFromBottom(mReverseLayout); } private void initRecylerView() { mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); mRecyclerAdapter = new MyRecyclerAdapter(); mRecyclerView.setAdapter(mRecyclerAdapter); mRecyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return !mScaledTouchSlop; } }); LinearLayoutManager manager = new LinearLayoutManager(this); //设置setReverseLayout 数据可以按照从头到尾或者从尾到头排序方式 manager.setReverseLayout(mReverseLayout); mRecyclerView.setLayoutManager(manager); } private View.OnClickListener mChangListener = new View.OnClickListener() { @Override public void onClick(View v) { mReverseLayout = !mReverseLayout; upDateView(); } }; private View.OnClickListener mOtherListener = new View.OnClickListener() { @Override public void onClick(View v) { mScaledTouchSlop = !mScaledTouchSlop; } }; private void upDateView() { //recyclerView LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); layoutManager.setReverseLayout(mReverseLayout); //listView mListView.setStackFromBottom(mReverseLayout); BaseAdapter adapter = (BaseAdapter) mListView.getAdapter(); }