今日头条(TodayNews)
仿今日头条的一个项目 (正在学习制作中)
现在包括Tablayout 和 侧拉 (slidingMenu) 这两个功能 逐渐完善中...
xutils3和tablayout 须要加的 在gradle里边 compile 'org.xutils:xutils:3.5.0' compile 'com.android.support:design:25.3.1'
侧拉须要导包
MainActivity(贴代码)
package com.example.lixin.todaynews; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import com.example.lixin.todaynews.adapter.MyPageAdapter; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private SlidingMenu slidingMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout); ImageView sliding_menu = (ImageView) findViewById(R.id.sliding_menu); sliding_menu.setOnClickListener(this); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(new MyPageAdapter(getSupportFragmentManager())); tabLayout.setupWithViewPager(viewPager); slidingMenu = new SlidingMenu(this); //设置一下侧滑菜单的位置 slidingMenu.setMode(SlidingMenu.LEFT); //设置触摸的区域 slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); //设置菜单打开时,内容区域的宽度 slidingMenu.setBehindOffset(300); //范围是 0 - 1f ,当设置成1的时候菜单栏有明显的褪色效果 slidingMenu.setFadeDegree(1.0f); //将slidingMenu和Activity关联起来 slidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT); slidingMenu.setMenu(R.layout.sliding_menu_layout); } @Override public void onClick(View v) { switch(v.getId()){ case R.id.sliding_menu: //自动控制开关,当前是开会关闭,如果是关闭就会打开 slidingMenu.toggle(); //第二种方式,通过判断是否正在显示 if (slidingMenu.isMenuShowing()){ slidingMenu.showContent(); }else { slidingMenu.showMenu(); } break; } } }
MyFragment
package com.example.lixin.todaynews; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; /** * Created by hua on 2017/8/2. */ public class MyFragment extends Fragment { private String text; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle arguments = getArguments(); text = arguments.getString("text"); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View inflate = inflater.inflate(R.layout.myfragment, container, false); TextView textView = (TextView) inflate.findViewById(R.id.tv_fragment); textView.setText(text); return inflate; } }
MyPageAdapter
package com.example.lixin.todaynews.adapter; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import com.example.lixin.todaynews.MyFragment; /** * Created by hua on 2017/8/2. */ public class MyPageAdapter extends FragmentPagerAdapter { private String[] titles = {"推荐", "热点", "北京", "视频", "军事娱乐", "热点", "北京", "视频", "军事娱乐"}; public MyPageAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { //new 我对应得fragment MyFragment myFragment = new MyFragment(); Bundle bundle = new Bundle(); bundle.putString("text",titles[position]); myFragment.setArguments(bundle); return myFragment; } //记得盘空 @Override public int getCount() { return titles.length; } //设置tablayout的每个tab的标题 @Override public CharSequence getPageTitle(int position) { return titles[position]; } }
下面贴布局xml
activity_main
<?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" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal"> <ImageView android:id="@+id/sliding_menu" android:layout_marginLeft="15dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ic_launcher" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal" > <android.support.design.widget.TabLayout android:id="@+id/tablayout" android:layout_width="match_parent" android:layout_height="40dp" app:tabMode="scrollable" app:tabIndicatorHeight="1dp" > </android.support.design.widget.TabLayout> <ImageView android:layout_width="40dp" android:layout_height="40dp" /> </LinearLayout> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v4.view.ViewPager> </LinearLayout>
sliding_menu_layout(侧拉界面)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:background="#ff0000" android:layout_width="match_parent" android:layout_height="150dp"> </RelativeLayout> <LinearLayout android:background="#00ff00" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" ></LinearLayout> <LinearLayout android:background="#0000ff" android:layout_width="match_parent" android:layout_height="100dp"> </LinearLayout> </LinearLayout>
AndroidManifestxml(配置界面)
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lixin.todaynews" > <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
今日头条(TodayNews)相关推荐
- 用Python打造属于自己的“今日头条” | 一个非常适合练手的全栈项目
项目简介 通过抓取微信文章和今日头条新闻,仿照今日头条,打造一个自己的今日头条 基本思路 新闻下载 -> 新闻存储 -> 新闻展示 抓取源: 今日头条app新闻 https://lf.sn ...
- Android仿今日头条的开源项目
起因 看到众多大神纷纷有了自己的开源项目,于是自己琢磨着也想做一个开源项目来学习下,因为每次无聊必刷的app就是今日头条,评论简直比内容都精彩,所以我打算仿今日头条来练练手,期间也曾放弃过,也遇到很多 ...
- 今日头条app数据包分析
数据包分析 wireshark+Connectify Hotspot(也可以是其他wifi共享工具), 参考:http://jingyan.baidu.com/article/19192ad85ca9 ...
- Android仿今日头条开源项目
起因 看到众多大神纷纷有了自己的开源项目,于是自己琢磨着也想做一个开源项目来学习下,因为每次无聊必刷的app就是今日头条,评论简直比内容都精彩,所以我打算仿今日头条来练练手,期间也曾放弃过,也遇到很多 ...
- Android 仿今日头条的开源项目
前言 看到众多大神纷纷有了自己的开源项目,于是自己琢磨着也想做一个开源项目来学习下,因为每次无聊必刷的 app 就是今日头条,评论简直比内容都精彩,所以我打算仿今日头条来练练手,期间也曾放弃过,也遇到 ...
- 哪种营销方法效果最差_今日头条广告投放形式分几种?头条品牌营销曝光效果哪种广告更好?...
一.今日头条广告形式分几种? 所以,广告主们也想借助今日头条投放广告.那么,今日头条怎么投放广告?今日头条平台有三种投放广告形式,开屏广告.信息流广告.详情页广告: 1.开屏广告 该广告位可以让你的产 ...
- android如何展示富文本_android高仿今日头条富文本编辑(发布文章)
前言: 在经历了几个月的项目期限.我们遇到了前端发布文章,要用到富文本编辑的功能.在一番衡量下最终用到了richeditor-android第三方框架.实现原理就是通过webView和js实现前端富文 ...
- 今日头条反爬措施形同虚设,论多平台协同在安全方面的重要性
点击上方↑↑↑蓝字[协议分析与还原]关注我们 " 玩头条练技能." 大家好,看到标题一定猜到了,我又来玩今日头条了,谁让它是东半球文明的杀时间神器呢. 想当年,头条刚问世,正愁长辈 ...
- Android屏幕适配框架-(今日头条终极适配方案)
2019独角兽企业重金招聘Python工程师标准>>> 在Android开发中,屏幕适配是一个非常头痛的问题,因而为了去进行屏幕适配,作为程序员,是呕心沥血,历经磨难,哈哈 我们之前 ...
最新文章
- 用C语言解“求特殊方程得正整数解”题
- Docker-Compose命令详解
- 内网端口转发-LCX基本使用
- 【Vegas2008】7月19日-凉粉的做法
- vue的实例属性$options
- 摄像头(WebCam)在Linux操作系统中的驱动方法
- everything如何搜索文件内容?(这软件搜索文件可以,搜索文件内容不行)
- Python爬虫反反爬:CSS反爬加密彻底破解!
- 吃西瓜—先磨刀之概率论
- java 密码库_JCA-Java加密框架
- 【CVPR2018】Deep Mutual Learning
- 高级前端面试题(来自一位朋友的投稿哟)
- 使用Python rembg库进行抠图:一行命令就搞定
- 论文题目:Spatiotemporal Multi-Graph Convolution Network for Ride-Hailing Demand Forecasting
- python下的考勤签到系统
- JavaScript基础语法(VS Code)
- B站粉丝数显示器代码解析学习
- IMS 会话过程 响应180还是183?
- java命令行调用格式工厂转码
- 福建省第二届“闽盾杯”部分Write Up