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

,点击变色也是自己用的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学习之仿微信主界面的更多相关文章
- Android ActionBar应用实战,高仿微信主界面的设计
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/26365683 经过前面两篇文章的学习,我想大家对ActionBar都已经有一个相对 ...
- Android利用ViewPager仿微信主界面-android学习之旅(78)
首先是介绍ViewPager这个控件 ,这个控件需要pagerAdapter作为容器来提供数据,同时pagerAdapter的数据源是View数组 效果图如下 部分代码如下,实现如下的方法 mPage ...
- 转-ViewPager组件(仿微信引导界面)
http://www.cnblogs.com/lichenwei/p/3970053.html 这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager ...
- 安卓开发笔记——ViewPager组件(仿微信引导界面)
这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager 什么是ViewPager? ViewPager是安卓3.0之后提供的新特性,继承自ViewGro ...
- Android 之高仿微信主界面
源码下载: http://files.cnblogs.com/aibuli/WeChatSample.zip 主界面主要使用ActionBar来完成. 要实现这个效果,第一步当然是编辑menu目录 ...
- [deviceone开发]-仿微信主界面示例
一.简介 模仿微信主界面的4个页面,作为一个很常规应用的框架模板,值得参考.另外包括简单的菜单,其中搜索还支持语音录入,不过你需要增加飞讯的语音组件重新打包,才能看到效果 二.效果图 三.相关下载 h ...
- 安卓开发笔记——Fragment+ViewPager组件(高仿微信界面)
什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开发复习笔记——ViewPager组件(仿微信引导界面)>,不清楚的朋友可以看看,这里就不再 ...
- 转-Fragment+ViewPager组件(高仿微信界面)
http://www.cnblogs.com/lichenwei/p/3982302.html 什么是ViewPager? 关于ViewPager的介绍和使用,在之前我写过一篇相关的文章<安卓开 ...
- [Android] Android 手机下 仿 微信 客户端 界面 -- 微聊
Android 手机下 仿 微信 客户端 界面 -- 微聊 (包括聊天列表 + 聊天对话页 + 朋友圈列表页 + 我的/发现 列表页) 项目演示: 功能说明: 1)底部标签切换 (TabHost + ...
随机推荐
- 说说windows10自带浏览器Edge的好与不好
用了10几个月了,正式版也升级了,今天来说说微软自带浏览器microsoft Edge的好与不好 先说好的吧 一,浏览器速度非常快,无论是打开还是关闭,或者是语音助手小娜需要调动浏 ...
- sehlle脚本获取linux服务器基本信息
将以下代码全选复制在linux机器上新建x.sh文件编辑复制进去执行即可. #获取linux服务器基本信息脚本 #!/bin/bash # #Name:system_info #Ver:1.0 #Au ...
- XML和JSON
XML XML(EXtensible Markup Language),可扩展标记语言 特点 XML与操作系统.编程语言的开发平台无关 实现不同系统之间的数据交换 作用: 数据交互 配置应用程序和网站 ...
- SQL SERVER系统表和常用函数介绍
sysaltfiles 主数据库 保存数据库的文件 syscharsets 主数据库 字符集与排序顺序sysconfigures 主数据库 配置选项syscurconfigs 主数据库 当前配置选项s ...
- RabbitMQ之项目中实战
说了那么多,还不是为了在项目中进行实战吗,在实践中检验真理,不然我学他干嘛,不能解决项目中的实际问题的技术都是耍流氓... 一.后台管理系统发送消息 瞎咧咧:后台管理系统发送消息到交换机中,然后通知其 ...
- React开发实时聊天招聘工具 -第四章 Redux
复杂以后 setState 就不太方便了 所以使用Redux来管理 React只负责View. Store.State.Dispatch.Reducer reducer(state,action) { ...
- 输出一定范围unicode对应符号
#本程序没有考虑对0x的处理,请勿输入,直接输入16进制位即可 begin = input("起始点:") end = input("结束点:") b_int0 ...
- Python使用selenium实现网页用户名 密码 验证码自动登录功能
一.安装selenium 二.下载谷歌浏览器驱动 1.去http://chromedriver.storage.googleapis.com/index.html下载chromedriver.exe( ...
- windows系统安装虚拟机VMware12,然后在虚拟机中安装Red Hat Enterprise Linux6操作系统
准备工作下载百度网盘: https://www.baidu.com/s?wd=%E7%99%BE%E5%BA%A6%E7%BD%91%E7%9B%98&rsv_spt=1&rsv_iq ...
- HTML5中手势原理分析与数学知识的实践
摘要:在这触控屏的时代,人性化的手势操作已经深入了我们生活的每个部分.现代应用越来越重视与用户的交互及体验,手势是最直接且最为有效的交互方式,一个好的手势交互,能降低用户的使用成本和流程,大大提高了用 ...