在JazzyViewPager中調用其它layout布局xml並使用,jazzyviewpager
開源地址:https://github.com/jfeinstein10/JazzyViewPager
發現網上的例子使用的是直接建立的一個TextView來做的。但是實際上使用,不可能只有這一個控制項。
下面是我的實現方式,如果大家有更好的方法,麻煩告之。不勝感激~~~
在自訂的
MainAdapter extends PagerAdapter
+ public Object instantiateItem(ViewGroup container, final int position) { 方法中的部分代碼實現如下:
View currView = null; LayoutInflater factory = LayoutInflater.from(context);currView = factory.inflate(getLayoutId(), null);//擷取控制項內容並設定click偵聽final RelativeLayout btnDebug = (RelativeLayout) currView.findViewById(R.id.btnDebug); Log.d("MainAdapter", "Button is null ?" + (btnDebug == null)); if (btnDebug != null) btnDebug.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d("DEBUG", "CLICK ME."); } });container.addView(currView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);jazzyPager.setObjectForPosition(currView, position);return currView;
即,要通過代碼的方式來實現載入layout中的布局XML,不知有沒有其它的辦法。