最近找申请到了一个不错的接口 , 非常适合拿来写一个资讯类的app.

现在着手写,随写随更.也算是抛砖引玉.烂尾请勿喷.╭(╯^╰)╮

android 资讯阅读器

第一阶段目标样式(滑动切换标签 , 侧滑菜单):

  

      图1                图2

首先我使用的ide 是android studio 2.0 已经集成了侧滑菜单的module

新建的时候选一下就好了.过程就不细说了.这个很简单.

下面就是实现滑动切换tab的效果啦.其实我这个写的并不是很好看,网上还有很多开源的滑动切寒tab的案例

盆友们可以自己去集成下.下面说下我的tab的实现效果(参考自:http://www.imooc.com/learn/264  大神鸿洋的慕课)

实现方法是viewpage+Fragment (单单用fragment并没有实现滑动效果).

如果你跟我一样用的是 图2 的模板 那么就要在content_main.xml下做如下修改

content_main.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.zfls.didainf.MainActivity"
tools:showIn="@layout/app_bar_main"
android:orientation="vertical"> <include layout="@layout/topbar"/> <android.support.v4.view.ViewPager
android:id="@+id/id_viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager> </LinearLayout>

使用的viewpage千万不要引入错咯.

topbar.xml :

<?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="wrap_content"
android:background="?attr/colorPrimary"
android:orientation="horizontal"> <LinearLayout
android:id="@+id/topical"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"> <TextView
android:id="@+id/topical_text_bg"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="center"
android:text="热点"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout> <LinearLayout
android:id="@+id/entertainment"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"> <TextView
android:id="@+id/entertainment_text_bg"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="center"
android:text="娱乐"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout> <LinearLayout
android:id="@+id/lettres"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"> <TextView
android:id="@+id/lettres_text_bg"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="center"
android:text="美文"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout> <LinearLayout
android:id="@+id/funny"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"> <TextView
android:id="@+id/funny_text_bg"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="center"
android:text="搞笑"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout> <LinearLayout
android:id="@+id/jokes"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"> <TextView
android:id="@+id/jokes_text_bg"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="center"
android:text="段子"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout> <LinearLayout
android:id="@+id/games"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"> <TextView
android:id="@+id/games_text_bg"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="center"
android:text="游戏"
android:textColor="#fff"
android:textSize="15dp" />
</LinearLayout> </LinearLayout>

很好理解, topbar 就是做一个顶部的布局,然后放到整体的布局中去.

效果如下(还不错 O(∩_∩)O哈!):

放进整体布局后就如 图1 的样子.

下面再创建一个布局文件用来做每个模块的容器

tab_topcial.xml :

<?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"> <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"> <ListView
android:id="@+id/tab_topical_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

这里说明下:

 <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">   ... </android.support.v4.widget.SwipeRefreshLayout>

SwipeRefreshLayout 是谷歌提供的下拉刷新模块.用它包裹listview 可以实现下拉刷新的效果(具体用法可以自行百度一下,或者等我再发一篇博客 嘿嘿)

下面是java代码了.

MainActivity.java :

package com.zfls.didainf;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.TextView; import java.util.ArrayList;
import java.util.List; public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener,View.OnClickListener { private ViewPager mViewPager;
private FragmentPagerAdapter mAdapter;
private List<Fragment> mFragments; //tab
private LinearLayout topical;
private LinearLayout entertainment;
private LinearLayout lettres;
private LinearLayout funny;
private LinearLayout jokes;
private LinearLayout games; private TextView topical_t;
private TextView entertainment_t;
private TextView lettres_t;
private TextView funny_t;
private TextView jokes_t;
private TextView games_t; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initside(); initView(); initWork(); setSelect(0);
}

   //统一监听
private void initWork() { topical.setOnClickListener(this);
entertainment.setOnClickListener(this);
lettres.setOnClickListener(this);
funny.setOnClickListener(this);
jokes.setOnClickListener(this);
games.setOnClickListener(this); }
   //声明相关控件
private void initView() {
mViewPager = (ViewPager) findViewById(R.id.id_viewpager); topical = (LinearLayout) findViewById(R.id.topical);
entertainment = (LinearLayout) findViewById(R.id.entertainment);
lettres = (LinearLayout) findViewById(R.id.lettres);
funny = (LinearLayout) findViewById(R.id.funny);
jokes = (LinearLayout) findViewById(R.id.jokes);
games = (LinearLayout) findViewById(R.id.games); topical_t = (TextView) findViewById(R.id.topical_text_bg);
entertainment_t = (TextView) findViewById(R.id.entertainment_text_bg);
lettres_t = (TextView) findViewById(R.id.lettres_text_bg);
funny_t = (TextView) findViewById(R.id.funny_text_bg);
jokes_t = (TextView) findViewById(R.id.jokes_text_bg);
games_t = (TextView) findViewById(R.id.games_text_bg); mFragments = new ArrayList<Fragment>();
Fragment mTab01 = new TopicalFragment();
Fragment mTab02 = new EntertainmentFragment();
Fragment mTab03 = new LetteresFragment();
Fragment mTab04 = new FunnyFragment();
Fragment mTab05 = new JokesFragment();
Fragment mTab06 = new GamesFragment();
mFragments.add(mTab01);
mFragments.add(mTab02);
mFragments.add(mTab03);
mFragments.add(mTab04);
mFragments.add(mTab05);
mFragments.add(mTab06); mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override
public android.support.v4.app.Fragment getItem(int position) {
return mFragments.get(position);
} @Override
public int getCount() {
return mFragments.size();
}
};
mViewPager.setAdapter(mAdapter); mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override
public void onPageSelected(int position) {
int currentItem = mViewPager.getCurrentItem();
setTab(currentItem);
} @Override
public void onPageScrollStateChanged(int state) { }
}); } //侧滑
private void initside() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
} @Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} return super.onOptionsItemSelected(item);
} @SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId(); if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) { } else if (id == R.id.nav_slideshow) { } else if (id == R.id.nav_manage) { } else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
} @Override
public void onClick(View v) {
switch (v.getId()){
case R.id.topical:
//热点
setSelect(0);
break;
case R.id.entertainment:
//娱乐
setSelect(1);
break;
case R.id.lettres:
//美文
setSelect(2);
break;
case R.id.funny:
//搞笑
setSelect(3);
break;
case R.id.jokes:
//段子
setSelect(4);
break;
case R.id.games:
//游戏
setSelect(5);
break; default:
break;
}
} private void setSelect(int i) {
setTab(i);
mViewPager.setCurrentItem(i);
}    //修改被选中的tab 文字的背景颜色(R.color.color.colorAccent 在 res/value/colors.xml 下)
private void setTab(int i) { changbg();
switch (i){
case 0:
topical_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorAccent));
break;
case 1:
entertainment_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorAccent));
break;
case 2:
lettres_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorAccent));
break;
case 3:
funny_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorAccent));
break;
case 4:
jokes_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorAccent));
break;
case 5:
games_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorAccent));
break;
}
}
   //将所有文字背景色改成未选中状态
private void changbg()
{
topical_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorWrite));
entertainment_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorWrite));
lettres_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorWrite));
funny_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorWrite));
jokes_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorWrite));
games_t.setTextColor(ContextCompat.getColor(MainActivity.this , R.color.colorWrite));
}
}

看起来挺多挺吓人,其实还好不算太多.

附件里面有鸿洋大神的demo,可以拿来移植一下.嘿嘿嘿

百度云链接 : http://pan.baidu.com/s/1boHCUbt

提取码:nhn2

移植完了以后就可以在手机上看下效果了.

android 资讯阅读器的更多相关文章

  1. android 资讯阅读器(二)

    接着上次的博客,上次移植完了tab以后整个app的框架就算是定下来了. 本次目标: 1.数据的获取与展示(ListView) 2.官方的下拉刷新效果(SwipeRefreshLayout) 3.数据接 ...

  2. android rss阅读器开发一点小技巧

    这几天一直在学习开发Rss阅读器,遇到一个很坑的问题,InputSource这里总是出错.弄了好久,终于让我找到一个解决方法----看代码: new Thread(){ @Override publi ...

  3. Android NurReaderView 阅读器 (字符串-.txt文件)

    有些地方还没配置好.2/3天后在更新.... 功能 支持字符串和<.txt>文件 文字自动分各个页面 支持从右到左-(从右边开始的语言.比如维吾尔语哈扎克语...外国的阿拉伯语等) 支持自 ...

  4. android优化中国风应用、完整NBA客户端、动态积分效果、文件传输、小说阅读器等源码

    Android精选源码 android拖拽下拉关闭效果源码 一款优雅的中国风Android App源码 EasySignSeekBar一个漂亮而强大的自定义view15 android仿蘑菇街,蜜芽宝 ...

  5. 电子书及阅读器Demo

    电子书阅读器(Kindle,电子纸技术.LCD.电子墨水技术等: 亚马逊/当当网站)  电子书产业可分5大环节:内容供应商.数字格式制作商.内容流通服务平台.传输平台以及终端阅读器产品. 全球电子书市 ...

  6. Android IT资讯网络阅读器应用源码

    这个是Android IT资讯网络阅读器应用,也是一款通过jsoup解析Html获取内容的网络阅读器,和前面的其实是类似的,也是大学时期闲暇完成,对照CSDN的Web页面元素设计进行解析提取内容,核心 ...

  7. Android 上的代码阅读器 CoderBrowserHD 修改支持 go 语言代码

    我在Android上的代码阅读器用的是 https://github.com/zerob13/CoderBrowserHD 改造的版本,改造后的版本我放在 https://github.com/ghj ...

  8. 将批量下载的博客导入到手机后,通过豆约翰博客阅读器APP(Android手机)进行浏览,白字黑底,保护眼睛,图文并茂。

    首先下面演示的博文来自于以下地址:http://www.douban.com/note/423939291/ 需要先通过博客备份专家将导出的博文导入到手机(还不会用的朋友请先阅读http://www. ...

  9. (android高仿系列)今日头条 --新闻阅读器 (三) 完结 、总结 篇

    从写第一篇今日头条高仿系列开始,到现在已经过去了1个多月了,其实大体都做好了,就是迟迟没有放出来,因为我觉得,做这个东西也是有个过程的,我想把这个模仿中一步一步学习的过程,按照自己的思路写下来,在根据 ...

随机推荐

  1. python curses使用

    python 中curses封装了c语言的curses,把c中复杂部分简单化,比如addstr(),mvaddstr(),mvwaddstr()合并成了一个addstr()方法. 一.语法入门 1.打 ...

  2. [转]在EntityFramework6中执行SQL语句

    本文转自:http://www.cnblogs.com/wujingtao/p/5412329.html 在上一节中我介绍了如何使用EF6对数据库实现CRDU以及事务,我们没有写一句SQL就完成了所有 ...

  3. [转]Oracle 分组聚合二种写法,listagg和wmsys.wm_concat

    本文转自:http://www.cnblogs.com/ycdx2001/p/3502495.html with temp as( select 'China' nation ,'Guangzhou' ...

  4. Pairs Forming LCM(素因子分解)

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/B    全题在文末. 题意:在a,b中(a,b<=n) ...

  5. AC日记——判断字符串是否为回文 openjudge 1.7 33

    33:判断字符串是否为回文 总时间限制:  1000ms 内存限制:  65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...

  6. Unity Ragdoll(布娃娃系统)

    逼真的动作如何实现的? 在一些游戏中当NPC或玩家死亡的时候,死亡的肢体动作十分逼真,这一物理现象如何用Unity来实现呢?Unity物理引擎中的Ragdoll系统,可以用来创建这种效果,具体请参阅以 ...

  7. 关于OAUTH2.0的极品好文

    Web Server Flow: web ServerFlow是把oauth1.0的三个步骤缩略为两个步骤 首先这个是适合有server的第三方使用的. 1客户端http请求authorize 2服务 ...

  8. 烈焰SWF解密

    SWF 解密 是用UE编辑器 改 SWF开头 的AA AA AA ,改成43 57 53 就解密了

  9. SVN的使用方法

    SVN的使用方法: 新建文件夹:文件夹1 在文件夹上点击右键--选择 SVN Checkout--弹出checkout窗口 下载文件的url获取:打开SVN--在要下载的文件上点击右键--点击Copy ...

  10. [No000013]在Office中关闭自动拼写检查和自动语法检查

    大家知道有时候语法检查很麻烦,搞得文档里都是红线和绿线.解决办法就是关闭自动拼写检查.现在我们来介绍怎么关闭office包括Word .Outlook .PowerPoint .OneNote .Pu ...