Android 仿QQ主页面的实
这一节讲一下QQ主页面的实现,先看一下官方效果图:
其中的好友,群组等既可以点击切换也卡,也可以滑动切换。所以,在实现的时候要同时使用两个手段。“会话”,“好友”等可以用Button来写,也可以是RadioButton,还可以是TextView,方法很多,在这里我选择了用TextView来做。而且这里的TextView要支持颜色的切换,默认一个暗白色,页卡停留在那是白色。总体来说还是比较简单的,下面看一下xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainQQActivity" ><RelativeLayoutandroid:id="@+id/headlayout"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/chat_bottom_send_pressed" ><ImageViewandroid:id="@+id/stateimage"android:layout_width="13dp"android:layout_height="13dp"android:layout_toRightOf="@+id/nametext"android:layout_marginLeft="10dp"android:layout_centerInParent="true"android:contentDescription="wq"android:src="@drawable/onlinestatus_online" /><ImageViewandroid:id="@+id/faceimage"android:layout_width="40dp"android:layout_height="40dp"android:layout_marginLeft="6dp"android:layout_marginTop="10dp"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:src="@drawable/qq" /><TextViewandroid:id="@+id/nametext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_marginLeft="14dp"android:layout_toRightOf="@+id/faceimage"android:text="JY"android:textColor="@color/color_bai"android:textSize="18dp" /></RelativeLayout>//这个Layout是最上面的头像,名称以及状态的布局。当然,也可以用LinearLayout来做。<LinearLayout android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/login_moremenu_back"android:orientation="vertical"><LinearLayout//这个LinearLayout用来显示四个标题android:id="@+id/bodylayout"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/login_moremenu_back"android:orientation="horizontal" ><TextViewandroid:id="@+id/speaktext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="5dp"android:layout_marginTop="5dp"android:layout_weight="1"android:gravity="center"android:text="会话"android:textColor="@drawable/text_color"android:textSize="18dp" /><TextViewandroid:id="@+id/fridenttext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="5dp"android:layout_marginTop="5dp"android:layout_weight="1"android:gravity="center"android:text="好友"android:textColor="@drawable/text_color"android:textSize="18dp" /><TextViewandroid:id="@+id/grouptext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="5dp"android:layout_marginTop="5dp"android:layout_weight="1"android:gravity="center"android:text="群组"android:textColor="@drawable/text_color"android:textSize="18dp" /><TextViewandroid:id="@+id/changetext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="5dp"android:layout_marginTop="5dp"android:layout_weight="1"android:gravity="center"android:text="动态"android:textColor="@drawable/text_color"android:textSize="18dp" /></LinearLayout><ImageView//这个就是下面的横杠图片android:id="@+id/cursor"android:layout_width="50dp"android:layout_height="6dp"android:layout_marginLeft="15dp"android:src="@drawable/meitu" /></LinearLayout><android.support.v4.view.ViewPager//不解释,用来滑动页卡android:id="@+id/vPager"android:layout_width="wrap_content"android:layout_height="0dp"android:layout_gravity="center"android:layout_weight="1.0"android:background="#000000"android:flipInterval="30"android:persistentDrawingCache="animation" /></LinearLayout>
有了上一篇《Android ViewPager使用详解 》的基础 ,Activity的代码就很容易理解了,我就不注释了。看一下Activity代码:
package com.example.imitateqq;import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
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.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;public class MainQQActivity extends Activity {private ViewPager viewPager;private ImageView imageView;private TextView textView1, textView2, textView3, textView4;private View view1, view2, view3, view4;private List<View> views;private int offSet = 0;// 动画图片偏移量private int currIndex = 0;// 当前页卡编号private int bmpW;// 动画图片宽度@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.mainqq);initView();initListener();}private void initView() {viewPager = (ViewPager) findViewById(R.id.vPager);imageView = (ImageView) findViewById(R.id.cursor);textView1 = (TextView) findViewById(R.id.speaktext);textView2 = (TextView) findViewById(R.id.fridenttext);textView3 = (TextView) findViewById(R.id.grouptext);textView4 = (TextView) findViewById(R.id.changetext);LayoutInflater layoutInflater = getLayoutInflater();view1 = layoutInflater.inflate(R.layout.qqtab_1, null);view2 = layoutInflater.inflate(R.layout.qqtab_2, null);view3 = layoutInflater.inflate(R.layout.qqtab_3, null);view4 = layoutInflater.inflate(R.layout.qqtab_4, null);views = new ArrayList<View>();views.add(view1);views.add(view2);views.add(view3);views.add(view4);bmpW=BitmapFactory.decodeResource(getResources(), R.drawable.a).getWidth();DisplayMetrics displayMetrics=new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);int screenW=displayMetrics.widthPixels;offSet=(screenW / 4 - bmpW) / 2;Matrix matrix=new Matrix();matrix.postTranslate(screenW, 0);imageView.setImageMatrix(matrix);}private void initListener() {textView1.setOnClickListener(new MyOnClickListener(0));textView2.setOnClickListener(new MyOnClickListener(1));textView3.setOnClickListener(new MyOnClickListener(2));textView4.setOnClickListener(new MyOnClickListener(3));viewPager.setAdapter(new MyPagerAdapter(views));viewPager.setOnPageChangeListener(new MyOnPageChangeListener());viewPager.setCurrentItem(0);textView1.setTextColor(getResources().getColor(R.color.color_bai));}private class MyPagerAdapter extends PagerAdapter {private List<View> mListViews;public MyPagerAdapter(List<View> mListViews) {this.mListViews = mListViews;}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {container.removeView(mListViews.get(position));}@Overridepublic Object instantiateItem(ViewGroup container, int position) {container.addView(mListViews.get(position));return mListViews.get(position);}@Overridepublic int getCount() {return mListViews.size();}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {return arg0 == arg1;}}private class MyOnPageChangeListener implements OnPageChangeListener {int one = offSet * 2 + bmpW;// 页卡1 -> 页卡2 偏移量public void onPageScrollStateChanged(int arg0) {}public void onPageScrolled(int arg0, float arg1, int arg2) {}public void onPageSelected(int arg0) {Animation animation = new TranslateAnimation(one*currIndex, one*arg0, 0, 0);currIndex = arg0;animation.setFillAfter(true);// True:图片停在动画结束位置animation.setDuration(300);imageView.startAnimation(animation);switch(currIndex){case 0:textView1.setTextColor(getResources().getColor(R.color.color_bai));textView2.setTextColor(getResources().getColor(R.color.title_bg));textView3.setTextColor(getResources().getColor(R.color.title_bg));textView4.setTextColor(getResources().getColor(R.color.title_bg));break;case 1:textView2.setTextColor(getResources().getColor(R.color.color_bai));textView1.setTextColor(getResources().getColor(R.color.title_bg));textView3.setTextColor(getResources().getColor(R.color.title_bg));textView4.setTextColor(getResources().getColor(R.color.title_bg));break;case 2:textView3.setTextColor(getResources().getColor(R.color.color_bai));textView2.setTextColor(getResources().getColor(R.color.title_bg));textView1.setTextColor(getResources().getColor(R.color.title_bg));textView4.setTextColor(getResources().getColor(R.color.title_bg));break;case 3:textView4.setTextColor(getResources().getColor(R.color.color_bai));textView2.setTextColor(getResources().getColor(R.color.title_bg));textView3.setTextColor(getResources().getColor(R.color.title_bg));textView1.setTextColor(getResources().getColor(R.color.title_bg));default :break;}}}private class MyOnClickListener implements OnClickListener {private int index = 0;public MyOnClickListener(int i) {index = i;}public void onClick(View v) {viewPager.setCurrentItem(index);switch(index){case 0:textView1.setTextColor(getResources().getColor(R.color.color_bai));textView2.setTextColor(getResources().getColor(R.color.title_bg));textView3.setTextColor(getResources().getColor(R.color.title_bg));textView4.setTextColor(getResources().getColor(R.color.title_bg));break;case 1:textView2.setTextColor(getResources().getColor(R.color.color_bai));textView1.setTextColor(getResources().getColor(R.color.title_bg));textView3.setTextColor(getResources().getColor(R.color.title_bg));textView4.setTextColor(getResources().getColor(R.color.title_bg));break;case 2:textView3.setTextColor(getResources().getColor(R.color.color_bai));textView2.setTextColor(getResources().getColor(R.color.title_bg));textView1.setTextColor(getResources().getColor(R.color.title_bg));textView4.setTextColor(getResources().getColor(R.color.title_bg));break;case 3:textView4.setTextColor(getResources().getColor(R.color.color_bai));textView2.setTextColor(getResources().getColor(R.color.title_bg));textView3.setTextColor(getResources().getColor(R.color.title_bg));textView1.setTextColor(getResources().getColor(R.color.title_bg));default :break;}}}
}
最后看一下效果图:
关于QQ的UI部分基本上就是这样,之后将引入服务器,实现通信的功能。当然,还有很多UI要写,比如聊天页面,设置页面等等,在用到的时候再去写。谢谢大家关注!
下载地址
Android 仿QQ主页面的实相关推荐
- android qq分组展开,Android仿qq分组管理的第三方库
本文实例为大家分享了Android仿qq分组管理的第三方库,供大家参考,具体内容如下 下面先看效果 我们点击展开与折叠分组的功能在库里面是已经封装好的,只能把它已入到项目中,就可以直接用了,十分的方便 ...
- android 仿qq修改头像,Qt:小项目仿QQ修改头像界面,技术点记录
最近写了一个修改头像功能的UI,布局参考了QQ目前的修改头像界面.如下图 这里主要说明一下两个地方的技术:1.头像图片上层的遮罩层,圆形外部为灰色,内部为全透明:2.上传图片宽高比例可以通过鼠标拖拽移 ...
- Android仿QQ主界面-------完善篇
在我前面的博文中,做出了仿QQ主界面的主要工作,博文地址:Android仿QQ主界面. 但是在那一篇中还有一个不起眼的地方没做,今天就完善它. 今天要实现在文字下面来个ImageView,实现动画.先 ...
- Android仿QQ空间底部菜单
之前曾经在网上看到Android仿QQ空间底部菜单的Demo,发现这个Demo有很多Bug,布局用了很多神秘数字.于是研究了一下QQ空间底部菜单的实现,自己写了一个,供大家参考.效果如下图所示: 点 ...
- Android仿QQ侧滑菜单
先上效果图: GIF图有点模糊,源码已上传Github:Android仿QQ侧滑菜单 ####整体思路: 自定义ItemView的根布局(SwipeMenuLayout extends LinearL ...
- Android仿QQ通讯录分组展示ExpandableListView
Android仿QQ通讯录分组展示ExpandableListView 核心是重写BaseExpandableListAdpter,其实和之前写的普通的BaseAdapter是类似的, 但是BaseE ...
- android 仿QQ,微信群组里的@功能,支持@多人,并能一键删除,能获取上传对应的id(修改版)
首先注明该文章是借签别人的博客,原文博文地址点击打开链接 android 仿QQ,微信群组里的@功能,支持@多人,并能一键删除,能获取上传对应的id 这个需求来源:本人做集成环信聊天时,项目需要@功能 ...
- android人脸识显示头像自定义,Android 仿QQ头像自定义截取功能
看了Android版QQ的自定义头像功能,决定自己实现,随便熟悉下android绘制和图片处理这一块的知识. 先看看效果: 思路分析: 这个效果可以用两个View来完成,上层View是一个遮盖物,绘制 ...
- Android仿QQ ios dialog,仿QQ退出向上菜单
Android仿QQ ios dialog,仿QQ退出向上菜单 EasyDialog两种模式 仿QQ退出向上菜单,自定义向上菜单 github地址:https://githu ...
最新文章
- opencv-python(PIL)图像处理之训练模型前的几种图预处理
- java万年历计算法定节假日,java获取中国节假日
- arcgis python工具-使用python制作ArcGIS插件(1)工具介绍
- python官网下载步骤linux-linux下安装python
- mysql中int、bigint、smallint 和 tinyint的区别与长度的含义
- 计算机网络:05---网络类型:局域网、城域网、广域网、个域网、无线网络
- 使用 yo 命令行向导创建 SAP UI5 应用
- 那些年,我们见过的 Java 服务端“问题”
- 深入理解Mysql - 内部架构与模块
- Spark: history Server
- Druid实用笔记001---Druid 介绍及配置
- open jdk 证书 问题
- 平面图设计软件测试自学,CAD平面自学网教程
- springCloud Alibaba 与 nacos
- Moto XT1085 国行 解锁BL
- matlab cramer法则,玩转线性代数(8)第一章第七节_克拉姆法则与秘密武器
- 关于GPS坐标系和地图定位偏差
- Windows 7安装.net framework 4 安装
- 单片机仿真软件Proteus Pro 8.9版本License过期
- [RK3566] 通过GM8775 点LVDS屏调试记录