我在片段API還算不錯,我知道如何創建手機/平板電腦的主/從模式。 但我怎麼會創造手機和平板電腦不同風格的導航?不同風格的導航 - 手機vs平板電腦?
最明顯的例子就是在手機上刷標籤和一些平板佈局,所有的碎片放在裏面,沒有滑動標籤。
難道還有比巨人if語句這樣其他的一些優雅的方式?
//編輯
所以,你會做什麼,我認爲,是創建創建兩個佈局(電話 - 查看傳呼機/平板電腦 - 三個靜態片段),並在活動的onCreate檢查佈局中的東西,弄清楚你是否在手機或平板電腦。 然後,只需初始化標籤導航/或不使用平板電腦。這應該工作。
中的代碼段IO 2012 APP
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
FragmentManager fm = getSupportFragmentManager();
mViewPager = (ViewPager) findViewById(R.id.pager);
if (mViewPager != null) {
// Phone setup
mViewPager.setAdapter(new HomePagerAdapter(getSupportFragmentManager()));
mViewPager.setOnPageChangeListener(this);
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.addTab(actionBar.newTab()
.setText(R.string.title_my_schedule)
.setTabListener(this));
actionBar.addTab(actionBar.newTab()
.setText(R.string.title_explore)
.setTabListener(this));
actionBar.addTab(actionBar.newTab()
.setText(R.string.title_stream)
.setTabListener(this));
homeScreenLabel = getString(R.string.title_my_schedule);
} else {
//Tablet setup
mExploreFragment = (ExploreFragment) fm.findFragmentById(R.id.fragment_tracks);
mMyScheduleFragment = (MyScheduleFragment) fm.findFragmentById(R.id.fragment_my_schedule);
mSocialStreamFragment = (SocialStreamFragment) fm.findFragmentById(R.id.fragment_stream);
}
}
任何你們已經對手機的標籤導航,請考慮在平板電腦上實現這一點,如果你在設計方面它的工作原理。你已經準備好碎片了,所以沒有任何藉口,真的。
你的意思是accomidate在屏幕大小的區別?即在手機上,我需要導航,因爲我不能在一個屏幕上,但在平板電腦上,在那裏我有更多的空間所有的片段,我可以在同一時間看到2或3。 – Rarw 2013-02-12 13:44:51