android-UI-切换fragment导航条---网易云探索(1)
来源:互联网 发布:淘宝内部优惠券微信号 编辑:程序博客网 时间:2024/04/28 10:21
今天查看了网易云音乐播放器的界面,想着如何实现的。现在尝试模仿一下。
参考文章:Fragment实例精讲——底部导航栏的实现
导航条实现
HorizontalScrollView+RadioButton
HorizontalScrollView是为了多个选项的设置,防止超出屏幕可以滚动。
activity.xml
<HorizontalScrollView android:id="@+id/huadong" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:scrollbars="none"> <RadioGroup android:id="@+id/rg_tab_bar" android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentBottom="true" android:background="#cccccc" android:orientation="horizontal"> <RadioButton android:id="@+id/rb_channel" style="@style/tab_menu_item" android:background="#ff0000" android:text="tab1" /> <RadioButton android:id="@+id/rb_message" style="@style/tab_menu_item" android:background="#0000dd" android:text="tab2" /> <RadioButton android:id="@+id/rb_better" style="@style/tab_menu_item" android:background="#00ff00" android:text="tab3" /> <RadioButton android:id="@+id/rb_setting" style="@style/tab_menu_item" android:background="#ccff00" android:text="tab4" /> </RadioGroup> </HorizontalScrollView>
Fragment设置
发现原来参考文章有错误。
public MyFragment(String content) { this.content = content; }
是错误的:不能使用重载传参
使用fragment注意事项:
1. fragment一定要有一个无参构造函数
2. 如果要给fragment传参,一定要使用Bundle方式传参,而不重载构造函数传参,因为在fragment重新生成的使用不会执行这个带参构造函数,而是执行无参构造函数。
所以应该这样传参:
Activity.class
fg4 = new MyFragment(); Bundle args = new Bundle(); args.putString("userId", "第四个Fragment"); fg4.setArguments(args); fTransaction.add(R.id.ly_content,fg4);
Fragment.class
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fg_content, container, false); TextView txt_content = (TextView) view.findViewById(R.id.txt_content); Bundle args = getArguments(); if (args != null) { userId = args.getString("userId"); } txt_content.setText(userId); return view; }
继续添加Fragment
<FrameLayout android:id="@+id/ly_content" android:layout_width="match_parent" android:layout_height="match_parent" ></FrameLayout>
0 0
- android-UI-切换fragment导航条---网易云探索(1)
- Android:Fragment实现带导航条的页面左右切换
- android-UI-viewpager--PagerTabStrip的使用---网易云探索(2)
- android--UI--导航条toolbar
- 模仿网易云课堂的底部导航栏切换—RadioButton+Fragment
- 针对下方是导航条,上方是Fragment; 包括Fragment再嵌套Fragment进行切换(类似QQ消息模块中消息,电话)的UI框架
- android基于Fragment实现底部导航切换
- Android UI-实现底部切换标签(fragment)
- Android UI-实现底部切换标签(fragment)
- Android UI-实现底部切换标签(fragment)
- Android UI-实现底部切换标签(fragment)
- Android个人学习笔记-底部导航切换Fragment的实现
- Android流行UI布局:底部导航(BottomNavigationView+ViewPager+Fragment)
- Android 导航条效果实现(五) ActionBar+Fragment
- Android 导航条效果实现(六) TabLayout+ViewPager+Fragment
- Android 底部导航条切换高亮的效果实现
- android FragmentTabHost切换Fragment时避免UI重新加载
- Fragment 实现日期导航条
- C$PU
- 一些面试问题
- C++的初始化顺序
- phpstorm 2016.2.1最新版本离线激活方法
- (剑指offer)链表
- android-UI-切换fragment导航条---网易云探索(1)
- c# ToolStrip控件中button控件 显示文字和图标——笔记
- 二维数组作为函数形参的函数声明
- Activiti数据库表结构
- leetcode Flatten Binary Tree to Linked List
- 2016年最新J2EE基础入门教程目录(完结版)
- 【poj1201】 Intervals
- Android-自定义图片加载框架
- 题目:用两个栈实现队列