由于素材的原因,这里都是从网上找的图片,所以所谓的仿微信实际上最后成了下图这货。。

。,点击变色也是自己用的windows自带绘图的颜料桶填充的空白。

。。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjU2NjY5Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

直接上主代码:

package com.example.tabandviewpage ;
import java.util.ArrayList;
import java.util.List; import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.LinearLayout; public class Main extends Activity implements OnClickListener{
private ViewPager viewpager ;
private ImageButton chat_list ,contacts ,friends,aboutme ;
private List<View> list ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE) ;
setContentView(R.layout.main);
list = new ArrayList<View>() ;
this.viewpager = (ViewPager) findViewById(R.id.viewpager) ;
initView() ;
this.chat_list.setOnClickListener(this);
this.contacts.setOnClickListener(this);
this.friends.setOnClickListener(this);
this.aboutme.setOnClickListener(this);
this.viewpager.setOnPageChangeListener(new OnPageChangeListener() { @Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
int position = viewpager.getCurrentItem() ;
resetImg();
if(position ==0)
{
chat_list.setImageResource(R.drawable.btn_chat_anxia);
} else if(position == 1) {
contacts.setImageResource(R.drawable.btn_contacts_anxia);
} else if(position == 2) {
friends.setImageResource(R.drawable.btn_rest_anxia);
} else if(position == 3) {
aboutme.setImageResource(R.drawable.btn_aboutme_anxia);
} } @Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub } @Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub }
}); }
void initView() {
// TODO Auto-generated method stub
this.chat_list = (ImageButton) findViewById(R.id.chat_list) ;
this.contacts = (ImageButton) findViewById(R.id.contacts) ;
this.friends = (ImageButton) findViewById(R.id.friends) ;
this.aboutme = (ImageButton) findViewById(R.id.aboutme) ; //LinearLayout tab_chat_list = (LinearLayout)findViewById(R.id.chat_list) ;
//LinearLayout tab_contacts = (LinearLayout)findViewById(R.id.tab_contacts) ;
//LinearLayout tab_friends = (LinearLayout) findViewById(R.id.tab_friends) ;
//LinearLayout tab_aboutme = (LinearLayout)findViewById(R.id.tab_aboutme) ; LayoutInflater mf = getLayoutInflater().from(this) ;
View tab_01 = mf.inflate(R.layout.tab_chat_list, null) ;
View tab_02 =mf.inflate(R.layout.tab_contacts, null) ;
View tab_03 = mf.inflate(R.layout.tab_friends, null) ;
View tab_04 = mf.inflate(R.layout.tab_aboutme, null) ; this.list.add(tab_01) ;
this.list.add(tab_02) ;
this.list.add(tab_03) ;
this.list.add(tab_04) ; PagerAdapter adapter = new PagerAdapter() { @Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0 == arg1 ;
} @Override
public int getCount() {
// TODO Auto-generated method stub
return list.size() ;
}
@Override
public void destroyItem(ViewGroup container, int position,
Object object) {
// TODO Auto-generated method stub
container.removeView(list.get(position));
} @Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
View view = list.get(position) ;
container.addView(view) ;
return view;
}
}; viewpager.setAdapter(adapter);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
resetImg() ;
switch(v.getId())
{
case R.id.chat_list:
this.chat_list.setImageResource(R.drawable.btn_chat_anxia);
viewpager.setCurrentItem(0);
break ; case R.id.contacts:
this.contacts.setImageResource(R.drawable.btn_contacts_anxia);
viewpager.setCurrentItem(1);
break ; case R.id.friends :
this.friends.setImageResource(R.drawable.btn_rest_anxia) ;
viewpager.setCurrentItem(2);
break ;
case R.id.aboutme :
this.aboutme.setImageResource(R.drawable.btn_aboutme_anxia);
viewpager.setCurrentItem(3);
break ; } }
private void resetImg() {
// TODO Auto-generated method stub
this.chat_list.setImageResource(R.drawable.btn_chat);
this.contacts.setImageResource(R.drawable.btn_contacts);
this.friends.setImageResource(R.drawable.btn_rest);
this.aboutme.setImageResource(R.drawable.btn_aboutme);
} }

主activity布局:

<?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" > <include layout="@layout/top"/> <android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/> <include layout="@layout/bottom"/> </LinearLayout>

顶部布局

<?

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="45dp"
android:background="#303030"
android:orientation="vertical" > <TextView
android:text="微信"
android:textColor="#FFFFFF"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"/> </LinearLayout>

底部布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:baselineAligned="false"
android:background="#FFFFFF"
android:layout_height="wrap_content"
android:orientation="horizontal" > <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="@+id/chat_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:src="@drawable/btn_chat"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="聊天"
android:textSize="20sp"/>
</LinearLayout> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="@+id/contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:src="@drawable/btn_contacts"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="联系人"
android:textSize="20sp"/>
</LinearLayout> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="@+id/friends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:src="@drawable/btn_rest"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="朋友圈"
android:textSize="15sp"/>
</LinearLayout> <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="@+id/aboutme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:src="@drawable/btn_aboutme"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="个人中心"
android:textSize="20sp"/>
</LinearLayout> </LinearLayout>

ViewPager学习之仿微信主界面的更多相关文章

  1. Android ActionBar应用实战,高仿微信主界面的设计

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/26365683 经过前面两篇文章的学习,我想大家对ActionBar都已经有一个相对 ...

  2. Android利用ViewPager仿微信主界面-android学习之旅(78)

    首先是介绍ViewPager这个控件 ,这个控件需要pagerAdapter作为容器来提供数据,同时pagerAdapter的数据源是View数组 效果图如下 部分代码如下,实现如下的方法 mPage ...

  3. 转-ViewPager组件(仿微信引导界面)

    http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...

  4. 安卓开发笔记——ViewPager组件(仿微信引导界面)

    这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager 什么是ViewPager? ViewPager是安卓3.0之后提供的新特性,继承自ViewGro ...

  5. Android 之高仿微信主界面

    源码下载:  http://files.cnblogs.com/aibuli/WeChatSample.zip 主界面主要使用ActionBar来完成.  要实现这个效果,第一步当然是编辑menu目录 ...

  6. [deviceone开发]-仿微信主界面示例

    一.简介 模仿微信主界面的4个页面,作为一个很常规应用的框架模板,值得参考.另外包括简单的菜单,其中搜索还支持语音录入,不过你需要增加飞讯的语音组件重新打包,才能看到效果 二.效果图 三.相关下载 h ...

  7. 安卓开发笔记——Fragment+ViewPager组件(高仿微信界面)

    什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开发复习笔记——ViewPager组件(仿微信引导界面)>,不清楚的朋友可以看看,这里就不再 ...

  8. 转-Fragment+ViewPager组件(高仿微信界面)

    http://www.cnblogs.com/lichenwei/p/3982302.html 什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开 ...

  9. [Android] Android 手机下 仿 微信 客户端 界面 -- 微聊

    Android 手机下 仿 微信 客户端 界面 -- 微聊 (包括聊天列表 + 聊天对话页 + 朋友圈列表页 + 我的/发现 列表页) 项目演示: 功能说明: 1)底部标签切换 (TabHost + ...

随机推荐

  1. swift 使用计算属性+结构管理内存

    class GooClass { deinit { print("aaaaaaaa") } var str = "gooClass" } struct GooS ...

  2. Python框架Django的入门

    本篇文章主要给大家介绍Django的入门知识:

  3. org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [********] will not be managed by Spring

    如下图,查看层次是否正确.

  4. filezilla server FTP 安装报错 "could not load TLS network. Aborting start of administration interface"

    filezilla server FTP 安装报错   "could not load TLS network. Aborting start of administration inter ...

  5. iOS缓存到sandbox

        在手机应用程序开发中,为了减少与服务端的交互次数,加快用户的响应速度,一般都会在iOS设备中加一个缓存的机制,前面一篇文章介绍了iOS设备的内存缓存,这篇文章将设计一个本地缓存的机制. 功能需 ...

  6. React入门介绍(2)- React Component-React组件

    React Component-React组件 允许用户自由封装组件是React非常突出的特性,用户可将自己创建的组件像普通的HTML标签一样插入页面,React.CreateClass方法就是用来创 ...

  7. sizeof 感知重载,模板具现, 转换规则

    问题:如何侦知任意型别 T 是否可以自动转换为型别 U? 方案:侦测转换能力的想法:合并运用 sizeof 和重载函数. 1 依赖 sizeof,sizeof 有着惊人的能力,你可以把 sizeof  ...

  8. HDOJ 1846 Brave Game - 博弈入门

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1846 经典基础博弈,首先面对(m+1)的人一定会输,依次往后推即可: #include<iost ...

  9. CF1000G Two-Paths

    题目大意:给你一棵树,其中点上和边上都有值.定义2-Path为经过一条边最多两次的路径,价值为经过点的权值加和-经过边权值*该边经过次数.4e5组询问,每次询问树上连接x,y两点的2-Path的最大价 ...

  10. 第二十节:Scrapy爬虫框架之使用Pipeline存储

    在上两节当中,我们爬取了360图片,但是我们需要将图片下载下来,这将如何下载和存储呢? 下边叙述一下三种情况:1.将图片下载后存储到MongoDB数据库:2.将图片下载后存储在MySQL数据库:3.将 ...