2016-08-24 138 views
0

我通過調整頁面邊距來實現類似查看尋呼機的caurosel。我能夠實現像下面PagerAdapter爲多視圖尋呼機返回錯誤的位置

enter image description here

,但我面臨的問題與PagerAdapter

@Override 
public Object instantiateItem(ViewGroup container, int position) { 
    View view= inflater.inflate(R.layout.mylayout, null); 

    // 
    Button btn=(Button)view.findViewById(R.id.button1); 
    btn.setTag(position); 
    btn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Log.e("position",v.getTag()+""); 
     } 
    } 
    return imgView; 
} 

雖然我設置的標籤,我能得到正確的位置僅中心網頁(選擇的項目),但是當我點擊左側頁面的按鈕時,它會返回錯誤的值。

我已經搜索了關於這個問題的很多,到目前爲止我找不到解決方案。

尋找你的幫助。

感謝

回答

0

您可以使用RecyclerView

LinearLayoutManager layoutManager = ... 
recyclerView.setLayoutManager(layoutManager); 

//when you want horizontal 
layoutManager.setOrientation(context,LinearLayoutManager.HORIZONTAL,false); 

//when you want vertical 
layoutManager.setOrientation(context,LinearLayoutManager.VERTICAL,false); 
+0

感謝快速效應初探。我正在工作在非常老的代碼基礎上。是否有任何與pagerAdapter的快速修復調整 – Senthil