简单好用的tab切换页面
2016-03-17 15:56
323 查看
闲来无事,总结下一个经常用到的tab切换的功能。
先上图:
这个是利用的RadioGroup和radiobutton实现点击切换tab功能,废话不说了,上代码吧!
涉及到一些drawable
cd_center_list_selector.xml
cd_center_bg_selected.xml
cd_left_list_bg_normal.xml
cd_rg_list.xml
list_text_selector.xml
cd_left_list_selector.xml
cd_left_list_bg_selected.xml
cd_left_list_bg_normal.xml
差不多就是这样,记录下,用的地方很多,方便下次再用!
先上图:
这个是利用的RadioGroup和radiobutton实现点击切换tab功能,废话不说了,上代码吧!
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <RadioGroup android:layout_width="match_parent" android:layout_below="@+id/icon" android:layout_height="40dp" android:layout_marginBottom="15dp" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:orientation="horizontal" android:background="@drawable/cd_rg_list" > <RadioButton android:id="@+id/rb_dai" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:button="@null" android:checked="true" android:gravity="center" android:background="@drawable/cd_left_list_selector" android:textColor="@drawable/list_text_selector" android:text="财富查询" /> <RadioButton android:id="@+id/rb_yi" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:button="@null" android:gravity="center" android:background="@drawable/cd_center_list_selector" android:textColor="@drawable/list_text_selector" android:text="近期收益" /> <RadioButton android:id="@+id/rb_er" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:button="@null" android:gravity="center" android:background="@drawable/cd_right_list_selector" android:textColor="@drawable/list_text_selector" android:text="推荐历史" /> </RadioGroup> <RelativeLayout android:id="@+id/rl_main" android:layout_width="match_parent" android:layout_height="match_parent"></RelativeLayout> </RelativeLayout>
涉及到一些drawable
cd_center_list_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/cd_center_bg_selected" android:state_checked="true"></item> <item android:drawable="@drawable/cd_center_bg_normal" android:state_checked="false"></item> </selector>
cd_center_bg_selected.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="0dp" android:topRightRadius="0dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" /> <solid android:color="@color/colorPrimary" /> </shape>
cd_left_list_bg_normal.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="5dp" android:topRightRadius="0dp" android:bottomLeftRadius="5dp" android:bottomRightRadius="0dp" /> <solid android:color="#00000000" /> </shape>
cd_rg_list.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 内部颜色 --> <solid android:color="#00000000" /> <!-- 边缘线条颜色 --> <stroke android:width="1dp" android:color="@color/colorPrimary" /> <!-- 圆角的幅度 --> <corners android:topLeftRadius="5dip" android:topRightRadius="5dip" android:bottomLeftRadius="5dip" android:bottomRightRadius="5dip" /> </shape>
list_text_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@android:color/white" android:state_checked="true" android:state_enabled="true" /> <item android:color="@android:color/black" /> </selector>
cd_left_list_selector.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/cd_left_list_bg_selected" android:state_checked="true"></item> <item android:drawable="@drawable/cd_left_list_bg_normal" android:state_checked="false"></item> </selector>
cd_left_list_bg_selected.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="5dp" android:topRightRadius="0dp" android:bottomLeftRadius="5dp" android:bottomRightRadius="0dp" /> <solid android:color="@color/colorPrimary" /> </shape>
cd_left_list_bg_normal.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:topLeftRadius="5dp" android:topRightRadius="0dp" android:bottomLeftRadius="5dp" android:bottomRightRadius="0dp" /> <solid android:color="#00000000" /> </shape>
差不多就是这样,记录下,用的地方很多,方便下次再用!
相关文章推荐
- 操作系统 实验一 命令解释程序的编写
- OpenStack 系列之Manila install and using the Virtualenv
- OpenStack 系列之Manila install and using the Virtualenv
- git 常用操作命令
- 安卓之多线程下载
- python 刷题:跳台阶
- Java获取来访者IP
- 机器学习实战笔记(四):Logist线性回归算法的Python实现
- python设置字体颜色
- 如何在网页中添加 jQuery。
- 在PL/SQL中怎样判断查询的结果是否为空
- Android 四大组件
- 14. Longest Common Prefix
- Hibernate含义
- JAVA学习【11】Servlet基础知识
- ILmerge 合并多个dll,并且设置默认程序集
- docker 创建镜像
- JSON与XML的区别比较
- Nginx + Tomcat集群 中取得远程用户IP问题的解决办法
- linux编译安装MySQL