我已經創建了一個應用程序,它有一個活動,其中有許多使用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);
}
}