我已经创建了一个应用程序,它有一个活动,其中有许多使用tablistener实现的片段。水平滑动手势检测Android
我现在想要在片段之间添加水平轻扫手势,但其证明非常困难。
我的第一个问题是,有没有办法检测基本活动内的滑动(即使是覆盖片段)?
或者用简单的滑动手势改造应用程序的最简单方法是什么?
下面骨架代码:
< ------------------主要活动--------------->
public class MainActivity extends FragmentActivity implements TabListener {
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tab = bar.newTab();
tab.setText("TAB1");
tab.setTabListener(this);
bar.addTab(tab);
tab = bar.newTab();
tab.setText("TAB2");
tab.setTabListener(this);
bar.addTab(tab);
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (tab.getPosition() == 0) {
Fragment newFragment = new Tab1Fragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
vb.vibrate(50);
}
< ------------------标签1个片段--------------->
public class Tab1Fragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.tab1_fragment, null);
}
}