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 + ...
随机推荐
- Python 保留n位小数
输出a, b 且保留三位小数 a = 2.3456 b = 2.0000 三种方法: round(a, 3)('%.3f' % a)Decimal(a).quantize(Decimal('0.000 ...
- 【Linux】CentOS tar压缩与解压命令大全
tar命令详解 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用 ...
- day24-1 元类
目录 元类 类的组成 内置函数 exec() class关键字创建类原理 自定义元类控制类的创建 自定义元类控制类实例化 自定义元类后对象属性查找顺序 元类 在python中一切皆对象,name我们用 ...
- 10 Steps To be a senior programmer
What 软件工程师的职业生涯要历经以下几个阶段:初级.中级,最后才是高级.这篇文章主要是讲如何通过 10 个步骤助你成为一名高级软件工程师. Why 得到更多的报酬!因为你的薪水会随着你水平的提高而 ...
- TensorFlow2-维度变换
目录 TensorFlow2-维度变换 Outline(大纲) 图片视图 First Reshape(重塑视图) Second Reshape(恢复视图) Transpose(转置) Expand_d ...
- MySQL-----增
增 **创建用户** create user 'alex'@'192.168.1.1' identified by '123123'; create user 'alex'@'192.168.1.%' ...
- linux下的文档处理及tar命令
1.使用cat命令进行纵向合并 使用‘>’是将左边的内容覆盖到右边 使用‘>>’是将左边的内容追加到右边文档中 还可使用‘>’将不同文件进行合并 2.管道符‘|’统计行数 使用 ...
- The Text Splitting (将字符串分成若干份,每份长度为p或q)
Description You are given the string s of length n and the numbers p, q. Split the string s to piece ...
- ExecutorService 线程池 (转发)
1.ExecutorService java.util.concurrent.ExecutorService 接口.用来设置线程池并执行多线程任务.它有以下几个方法. Future<?> ...
- jQuery学习之------对标签属性的操作
jQuery学习之------标签的属性 <a href=””>链接</a>此处的href就是该a标签带有的属性 在js中对标签的属性的操作方法有 1.1getAttribut ...