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 + ...
随机推荐
- ARM开发板如何选型-I.MX6Q开发板
拥有丰富扩展能力,供货周期长的开发平台,省事安心 处理器:迅为-i.MX6开发板恩智浦Cortex-A9 四核i.MX6Q处理器,主频1GHz,内存2G,存储16GB. 系统支持:i.MX6开发板 ...
- redis新特性
摘自<redis 4.xcookbook> 从实例重启同步] 故障切换同步] 4.0之前从实例主键过期bug redis4新特性 Memory Command Lazy Free PSYN ...
- jdk11 eclipse下开启ZGC
平台支持 ZGC目前只在Linux/x64上可用,如果有足够的需求,将来可能会增加对其他平台的支持. 对的,目前只支持64位的linux系统. -_-' eclipse.ini配置: -XX:+Unl ...
- 去掉PhpStorm打开自动启动的项目
有时候启动的项目很大,导致很卡,而且在编辑器中更改也没效果,简单暴力的办法 找到项目的目录,删除其中的.idea文件夹
- C++ 之 string
C++ 的 string 类封装了很多对字符串的常用操作. string 类是模板类 basic_string类,以 char作为其元素类型的类. string 以单字节作为一个字符,如果处理多字符集 ...
- action类中属性驱动和模型驱动的区别
1.Struts2的属性驱动 在Action类中,属性××通过get××()和set××()方法,把参数在整个生命周期内进行传递,这就是属性驱动 代码如下: package org.abu.csdn. ...
- Java中Date类型的工具类
package com.mytripod.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import ja ...
- Sax解析xml文档
测试的xml数据: <?xml version="1.0" encoding="utf-8" ?> <note> <to>G ...
- 关于使用mongodb中遇到的时间戳雷同的问题
文不对题,实际上不是时间戳,而是我们使用js取当前毫秒数,将他看为时间戳,每次updata的时候,获取当前毫秒数,把它当做create_time的默认值,自动添加到我们的数据库中,数据模型如下 开始的 ...
- postman工具的应用实战(二)
在接口测试工具中,最好的应该是soapui,jmeter,postman,但是soapui需要安装和破解,当然也是有破解版的,但是不够灵活,jmeter工具 做接口测试还是性能测试,功能测试,都是一个 ...