基于数据挖掘的旅游推荐APP(二):主界面布局
生活随笔
收集整理的這篇文章主要介紹了
基于数据挖掘的旅游推荐APP(二):主界面布局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??????? 主界面布局通過Fragment實現,底部類似于Tab選項卡,效果如下:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
??????? 底部導航欄是借鑒GitHub上的一個項目,不對,其實就是抄的。附上原地址鏈接,把庫引進來直接用就行了。下面上代碼:
??? activity_fragment.xml
??? LaunchActivity.java
public class LaunchActivity extends AppCompatActivity {private Fragment mFragmentLaunch;private Fragment mFragmentRecommend;private Fragment mFragmentRoute;private Fragment mFragmentUser;@Overridepublic void onCreate( Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_fragment);initView();selectTab(0);}/*** 初始化布局*/private void initView(){BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigation);BottomNavigationItem bottomNavigationItem = new BottomNavigationItem("熱點", ContextCompat.getColor(this, R.color.firstColor), R.drawable.hotspot);BottomNavigationItem bottomNavigationItem1 = new BottomNavigationItem("推薦", ContextCompat.getColor(this, R.color.secondColor), R.drawable.recommend);BottomNavigationItem bottomNavigationItem2 = new BottomNavigationItem("路線", ContextCompat.getColor(this, R.color.thirdColor), R.drawable.route);BottomNavigationItem bottomNavigationItem3 = new BottomNavigationItem("我的", ContextCompat.getColor(this, R.color.fourthColor), R.drawable.me);bottomNavigationView.addTab(bottomNavigationItem);bottomNavigationView.addTab(bottomNavigationItem1);bottomNavigationView.addTab(bottomNavigationItem2);bottomNavigationView.addTab(bottomNavigationItem3);bottomNavigationView.setOnBottomNavigationItemClickListener(new OnBottomNavigationItemClickListener() {@Overridepublic void onNavigationItemClick(int index) {selectTab(index);}});}/*** 進行選中Tab的處理* @param i*/private void selectTab(int i){//獲取FragmentManager對象FragmentManager manager = getSupportFragmentManager();//獲取FragmentTransaction對象FragmentTransaction transaction = manager.beginTransaction();//先隱藏所有的FragmenthideFragments(transaction);switch (i) {//當選中點擊的是熱點的Tab時case 0://如果熱點對應的Fragment沒有實例化,則進行實例化,并顯示出來if (mFragmentLaunch == null) {mFragmentLaunch = LaunchFragment.newInstance();transaction.add(R.id.fragment_container, mFragmentLaunch);} else {//如果熱點對應的Fragment已經實例化,則直接顯示出來transaction.show(mFragmentLaunch);}break;case 1:if (mFragmentRecommend == null) {mFragmentRecommend = RecommendFragment.newInstance();transaction.add(R.id.fragment_container, mFragmentRecommend);} else {transaction.show(mFragmentRecommend);}break;case 2:if (mFragmentRoute == null) {mFragmentRoute =RouteFragment.newInstance();transaction.add(R.id.fragment_container, mFragmentRoute);} else {transaction.show(mFragmentRoute);}break;case 3:if (mFragmentUser == null) {mFragmentUser =UserCenterFragment.newInstance();transaction.add(R.id.fragment_container, mFragmentUser);} else {transaction.show(mFragmentUser);}break;}//不要忘記提交事務transaction.commit();}//將四個的Fragment隱藏private void hideFragments(FragmentTransaction transaction) {if (mFragmentLaunch != null) {transaction.hide(mFragmentLaunch);}if (mFragmentRecommend != null) {transaction.hide(mFragmentRecommend);}if (mFragmentRoute != null) {transaction.hide(mFragmentRoute);}if (mFragmentUser != null) {transaction.hide(mFragmentUser);}} } ??????? 關于底部四個tab對應的fragment會在下面的博客中呈上。總結
以上是生活随笔為你收集整理的基于数据挖掘的旅游推荐APP(二):主界面布局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于数据挖掘的旅游推荐APP(一):开篇
- 下一篇: 基于数据挖掘的旅游推荐APP(三):热门