Android仿QQ空间主页面的实现

2016-02-19 11:00 71 1 收藏

在这个颜值当道,屌丝闪边的时代,拼不过颜值拼内涵,只有知识丰富才能提升一个人的内在气质和修养,所谓人丑就要多学习,今天图老师给大家分享Android仿QQ空间主页面的实现,希望可以对大家能有小小的帮助。

【 tulaoshi.com - 编程语言 】

今天模仿安卓QQ空间,效果如下:
  
打开程序的启动画面和导航页面我就不做了,大家可以模仿微信的那个做一下,很简单。这次主要做一下主页面的实现,下面是主页面的布局:
代码如下:

?xml version="1.0" encoding="utf-8"?
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical"
include
android:id="@+id/top_layout"
layout="@layout/main" /
/LinearLayout

里面引用了main这个布局文件,它的xml文件为:
代码如下:

?xml version="1.0" encoding="utf-8"?
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentTop="true"
android:background="@drawable/navbar_bg"
TextView
android:id="@+id/titltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的空间动态"
android:textSize="20dp"
android:layout_centerInParent="true"
/
ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/navbar_drop_down"
android:id="@+id/bytextimage1"
android:layout_toRightOf="@id/titltext"
/
ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/navbar_drop_up"
android:id="@+id/bytextimage2"
android:visibility="invisible"
android:layout_toRightOf="@id/titltext"
/
ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:src="@drawable/icon_refresh_none" /
/RelativeLayout//这个RelativeLayout是最上面“我的空间动态”那一部分的布局
FrameLayout //下面的导航栏的实现,他的背景就是灰色横条的那一部分
android:layout_width="fill_parent"
android:layout_height="65.32999dip"
android:layout_alignParentBottom="true"
android:background="@drawable/toolbar_bg"
LinearLayout //用来包含图片以及文字
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_gravity="bottom"
android:baselineAligned="false"
android:gravity="center_horizontal"
android:orientation="horizontal"
FrameLayout //采用帧布局,这样图片和文字就可以一起显示了。当然也可以用相对布局,一个在上,一个在下。
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_weight="1.0"
ImageView
android:layout_width="28.0dip"
android:layout_height="28.0dip"
android:layout_gravity="top|center"
android:layout_marginTop="1.0dip"
android:contentDescription=""
android:src="@drawable/tab_timefeed_opacity"
android:visibility="visible" /
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="6.0dip"
android:text="好友动态"
android:textColor="#ffffffff"
android:textSize="10.0dip"
android:visibility="visible" /
/FrameLayout
FrameLayout
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_marginRight="10.0dip"
android:layout_weight="1.0"
ImageView
android:layout_width="27.0dip"
android:layout_height="27.0dip"
android:layout_gravity="top|center"
android:layout_marginTop="1.0dip"
android:src="@drawable/tab_feedback_opacity"
android:visibility="visible" /
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="6.0dip"
android:text="与我相关"
android:textColor="#ffffffff"
android:textSize="10.0dip"
android:visibility="visible" /
TextView
android:layout_width="17.0dip"
android:layout_height="17.0dip"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15.0dip"
android:layout_marginLeft="10.0dip"
android:background="@drawable/myhome_visitor_number"
android:gravity="center_vertical"
android:paddingBottom="5.0dip"
android:paddingLeft="5.0dip"
android:paddingRight="0.0dip"
android:paddingTop="0.0dip"
android:text="n"
android:textColor="#ffffffff"
android:textSize="13.0dip"
android:visibility="visible" /
/FrameLayout
FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" /
FrameLayout
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_marginLeft="10.0dip"
android:layout_weight="1.0"
ImageView
android:layout_width="27.0dip"
android:layout_height="27.0dip"
android:layout_gravity="top|center"
android:layout_marginTop="1.0dip"
android:src="@drawable/tab_myzone_opacity"
android:visibility="visible" /
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="6.0dip"
android:text="主页"
android:textColor="#ffffffff"
android:textSize="10.0dip"
android:visibility="visible" /
/FrameLayout
FrameLayout
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_weight="1.0"
ImageView
android:layout_width="27.0dip"
android:layout_height="27.0dip"
android:layout_gravity="top|center"
android:layout_marginTop="1.0dip"
android:src="@drawable/tab_applist_opacity"
android:visibility="visible" /
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="6.0dip"
android:text="应用"
android:textColor="#ffffffff"
android:textSize="10.0dip"
android:visibility="visible" /
/FrameLayout
/LinearLayout
FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
ImageView
android:layout_width="66.666595dip"
android:layout_height="65.33328dip"
android:layout_gravity="center"
android:src="@drawable/toolbar_write_bg" /
/FrameLayout
FrameLayout
android:id="@+id/btn_ck"
android:layout_width="65.33328dip"
android:layout_height="65.33328dip"
android:layout_gravity="center"
ImageView
android:id="@+id/image1"
android:layout_width="22.666595dip"
android:layout_height="22.666595dip"
android:layout_gravity="center"
android:layout_marginTop="2.0dip"
android:src="@drawable/toolbar_plus" /
/FrameLayout
/FrameLayout
/RelativeLayout

上面的“我的空间动态”以及下面的圆形Button用的是PopubWindow,Activity的代码如下:
代码如下:

package com.example.imitateqqzone;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
public class ImitateQQZone extends Activity {
private PopupWindow popupWindow1,popupWindow2;
private ListView lv_group;
private View view, top_layout;
private TextView tvtitle;
private ListString groups;
//private int screenWidth,screenHeight,dialgoWidth,dialgoheight;
private ImageView byTextImageView1,byTextImageView2,centerimage;
//private int[] images={R.drawable.navbar_drop_down,R.drawable.navbar_drop_up};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_imitate_qqzone);
top_layout = this.findViewById(R.id.top_layout);
tvtitle = (TextView) top_layout.findViewById(R.id.titltext);
byTextImageView1=(ImageView) top_layout.findViewById(R.id.bytextimage1);
byTextImageView2=(ImageView) top_layout.findViewById(R.id.bytextimage2);
centerimage=(ImageView) findViewById(R.id.image1);

/*
* android view setVisibility():
有三个参数:Parameters:visibility One of VISIBLE, INVISIBLE, or GONE,想对应的三个常量值:0、4、8
VISIBLE:0 意思是可见的
INVISIBILITY:4 意思是不可见的,但还占着原来的空间
GONE:8 意思是不可见的,不占用原来的布局空间
*/
tvtitle.setOnClickListener(new OnClickListener() {
boolean isImage=false;
public void onClick(View v) {
showWindow1(v);
if(isImage==false){
isImage=true;
byTextImageView1.setVisibility(4);
byTextImageView2.setVisibility(0);

}else{
isImage=false;
byTextImageView1.setVisibility(0);
byTextImageView2.setVisibility(4);
}
}
});

centerimage.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
showWindow2(v);

}
});

}
protected void showWindow2(View v) {
if (popupWindow2 == null) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.pubmenu, null);
popupWindow2 = new PopupWindow(view, 400, 400);// 创建一个PopuWidow对象
}
popupWindow2.setFocusable(true); // 使其聚集
popupWindow2.setOutsideTouchable(true);// 设置允许在外点击消失
popupWindow2.setBackgroundDrawable(new BitmapDrawable());// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popupWindow2.showAsDropDown(v);

}
private void showWindow1(View parent) {
if (popupWindow1 == null) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.group_list, null);
lv_group = (ListView) view.findViewById(R.id.lvGroup);
// 加载数据
groups = new ArrayListString();
groups.add("全部动态");
groups.add("好友动态");
groups.add("特别关心");
groups.add("认证空间");
GroupAdapter groupAdapter = new GroupAdapter(this, groups);
lv_group.setAdapter(groupAdapter);
// 创建一个PopuWidow对象
popupWindow1 = new PopupWindow(view, 200, 350);
}

popupWindow1.setFocusable(true); // 使其聚集
popupWindow1.setOutsideTouchable(true);// 设置允许在外点击消失
popupWindow1.setBackgroundDrawable(new BitmapDrawable());// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景

//screenWidth = ImitateQQZone.this.getWindowManager().getDefaultDisplay().getWidth();
//screenHeight = ImitateQQZone.this.getWindowManager().getDefaultDisplay().getHeight();
//dialgoWidth = popupWindow.getWidth();
//dialgoheight = popupWindow.getHeight();
//int xPos =(screenWidth-dialgoWidth)/2;// 显示的位置为:屏幕的宽度的一半-PopupWindow的宽度的一半
//Log.i("coder", "xPos:" + xPos);

popupWindow1.showAsDropDown(parent);
lv_group.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView? adapterView, View view,
int position, long id) {
Toast.makeText(ImitateQQZone.this, groups.get(position), 1000)
.show();
// switch (position) {
// case 0:
// Intent intent = new Intent(ImitateQQZone.this,
// PopupWindowDemo2.class);
// startActivity(intent);
// /break;
// default:
// break;
// }
if (popupWindow1 != null) {
popupWindow1.dismiss();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_imitate_qqzone, menu);
return true;
}
}

其他的布局文件我就不贴出了,需要代码的可以@我或在下面留言,这只是个Demo,因为时间关系,还有很多细节没有实现。大家可以在我的基础上继续完善。

来源:https://www.tulaoshi.com/n/20160219/1596318.html

延伸阅读
标签: 电脑入门
手机QQ空间(Android)软件版具备以下功能: 1、可以实时好友动态更新; 2、高品质的好友照片查看; 3、看详情、写说说一站式社交互动体验 4、好友动态可以快捷评论、回复和转发。 5、全新个人主页,可以充分了解你的好友,说说、日志、相册和留言想看就看。 于2012-03-16号更新版本新增内容如下: 1、图片支持断点续传,更节约流量。 2、...
标签: 电脑入门
问题描述:若QQ空间进入后页面空白,一直都在加载进入的状态中。如图: 解决方案: 一、检查电脑网络状态; 1、可尝试打开网站:www.qq.com,查看您的网络连接是否正常; 2、测试空间链接是否正常:请您点击电脑屏幕左下角的开始=》运行=》输入Ping user.qzone.qq.com -t后,请留意数据返回的时间,一般Time在100ms以下基本都是能正常打...
标签: 电脑入门
问题描述:QQ空间进入后,空间内容及装扮显示重叠、错位、显示不完整等异常现象。如图: 解决方案: 一、清空IE缓存; 1、清空IE缓存可以有效提高电脑访问网站的速度,清空IE缓存方法请点击这里查看; 2、优化系统性能(您可以使用QQ电脑管家、超级兔子等)。 二、退出杀毒软件、上网助手、防火墙,取消浏览器屏蔽设置; TT浏览器取消屏蔽...
标签: Web开发
只修改了2个地方: ,返回的速度--改成了慢慢回去。(原来是一闪而返回) ,返回顶部图标出现的时机--改成了只要不在顶部就显示出来。(原来是向下滚动500px后才显示) 注意:JS务必要写在 Html之后; HTML 代码如下: div id="d-top" style="display:none;" a id="d-top-a" href="#" img src="http://img.warting.com/allimg/2015...
标签: 电脑入门
腾讯的QQ空间里有不少漂亮的qq空间皮肤和挂件,可是都要q币呀,那我们穷人怎么用呢?嘿嘿,办法还是有的,现在站长就教大家一个简单的方法来免费使用tx官方的QQ空间皮肤、挂件和Banner,道理都是是一样的,就是用QQ相册来实现。 下面以挂件为例子,举例说明如何获得图片地址以及图片的宽度和高度(其他的像皮肤、banner都是一样的哦)...

经验教程

152

收藏

75
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部