尚硅谷Android项目之_硅谷商城项目全套源码解析(五、发现)
来源:互联网 发布:罗技鼠标驱动 知乎 编辑:程序博客网 时间:2024/04/29 22:05
一、简介
承接上文:尚硅谷Android项目之_硅谷商城项目全套源码解析(四、分类)
上篇博客概括的介绍了硅谷商城项目的分类模块技术要点。本篇内容给大家讲解硅谷商城项目发现模块,发现模块用的技术包括:采用TabLayout实现标题的切换、采用OpenDanmaku实现弹幕功能、数据解析采用Gson。
二、详细资源地址
由于篇幅所限,详情情况见如下地址视频和笔记
项目免费视频讲解下载地址:http://www.atguigu.com/download.shtml
github地址:https://github.com/atguigu01/Shopping
作者:大海哥
三、效果演示:
四、技术详情
1、采用TabLayout实现标题的切换
1)导包
compile'com.android.support:design:24.2.1'
2)布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="5dp">
<ImageButton
android:id="@+id/ib_community_icon"
android:layout_width="40dp"
android:scaleType="fitXY"
android:layout_height="40dp"
android:background="@drawable/top_btn"/>
<TextView
android:textSize="18sp"
android:textColor="@android:color/background_dark"
android:gravity="center"
android:text="社区"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton
android:id="@+id/ib_community_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/community_message_icon"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#22000000"/>
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
3)设置样式
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
style="@style/MyCustomTabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
// 在styles.xml文件里面
<stylename="MyCustomTabLayout"parent="Widget.Design.TabLayout">
<item name="tabMaxWidth">52dp</item>
<item name="tabMinWidth">52dp</item>
<item name="tabIndicatorColor">#ff0000</item>
<item name="tabIndicatorHeight">2dp</item>
<item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
<item name="tabSelectedTextColor">@android:color/holo_red_light</item>
</style>
<style name="MyCustomTabTextAppearance"parent="TextAppearance.Design.Tab">
<item name="android:textSize">18sp</item>
<item name="android:textColor">@android:color/black</item>
<item name="textAllCaps">false</item>
</style>
4)代码:
tablayout= (TabLayout) view.findViewById(R.id.tablayout);
@Override
public void initData() {
super.initData();
CommunityViewPagerAdapter adapter = new CommunityViewPagerAdapter(getFragmentManager());
viewPager.setAdapter(adapter);
tablayout.setupWithViewPager(viewPager);
//如果有多个ViewPager页面
tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);
}
2、采用OpenDanmaku实现弹幕功能
详情使用情况见:https://github.com/linsea/OpenDanmaku
3、数据解析采用Gson
private void processData(String json) {
HotPostBean hotPostBean = JSONObject.parseObject(json,HotPostBean.class);
result = hotPostBean.getResult();
}
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(五、发现)
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(一、综述)
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(二、主框架搭建)
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(三、首页)
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(四、分类)
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(六、个人中心)
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(七、购物车)
- 尚硅谷·网上书城项目(五)
- 尚硅谷_Banking项目的那些事
- 尚硅谷Java视频教程,全套java视频
- 3. 尚硅谷_佟刚_JavaWEB_使用 Eclipse 开发 JavaWEB 项目.wmv
- 【备忘】尚硅谷Java视频_项目:数据采集系统 视频教程 共52课时
- 20. 尚硅谷_佟刚_SpringMVC_ModelAttribute注解之源码分析(无写笔记)
- 尚硅谷·网上书城项目(一)
- 尚硅谷·网上书城项目(二)
- 尚硅谷·网上书城项目(三)
- 尚硅谷·网上书城项目(四)
- 尚硅谷·网上书城项目(六)
- java连接mysql的步骤
- Firebox比较常用的插件
- subarray 划分类
- nginx随笔
- 流失的岁月
- 尚硅谷Android项目之_硅谷商城项目全套源码解析(五、发现)
- 移动端rem设置
- 浅谈数学专业角度下的目标管理方法
- 一位女孩
- Linux内核中的IPSEC实现1
- 时间不曾停留
- Linux内核中的IPSEC实现2
- 致玉芬之话语
- CentOS7下搭建Zabbix2.2