【发布时间】:2014-03-06 01:23:59
【问题描述】:
我已经创建了一个应用程序,该应用程序具有一个 Activity,该 Activity 具有许多使用 tablistener 实现的片段。
我现在想在片段之间添加水平滑动手势,但事实证明非常困难。
我的第一个问题是,有没有办法只检测基本活动中的滑动(即使覆盖了片段)?
或者用简单的滑动手势来改造应用程序的最简单方法是什么?
下面的骨架代码:
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);
}
public class Tab1Fragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.tab1_fragment, null);
}
}
【问题讨论】:
标签: android fragment gesture swipe-gesture android-gesture