高效開發-使用7.0 sdk 開發ViewPager 翻頁每個ITem 居中
阿新 • • 發佈:2019-02-05
1.
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
2.
package com.org.gsc.rvabout; import android.app.Activity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.PagerSnapHelper; import android.support.v7.widget.RecyclerView; importcom.org.gsc.rvabout.adapter.MyAdapter; import com.org.gsc.rvabout.utils.RvUtils; import com.org.gsc.rvabout.utils.Urls; public class MainActivity extends Activity { private RecyclerView mRecyclerView; String[] urls= Urls.urls; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRecyclerView=findViewById(R.id.rv); RvUtils.RvSetingUtils(mRecyclerView,new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false),new MyAdapter(this,urls)); //一次可以多頁滑動水平和垂直方向都可以支援但是每頁還是居中顯示在手機螢幕 // LinearSnapHelper linearSnapHelper=new LinearSnapHelper();// linearSnapHelper.attachToRecyclerView(mRecyclerView); //一次只能快速滑動一頁相當於ViewPager 但是每頁還是居中顯示在手機螢幕 PagerSnapHelper p=new PagerSnapHelper(); p.attachToRecyclerView(mRecyclerView); } }