Android仿QQ空间

 今天模仿安卓QQ空间,效果如下:

  

  打开程序的启动画面和导航页面我就不做了,大家可以模仿微信的那个做一下,很简单。这次主要做一下主页面的实现,下面是主页面的布局:




    

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



    

    

        
        
         
        
        
    //这个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 List 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 ArrayList();
			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,因为时间关系,还有很多细节没有实现。大家可以在我的基础上继续完善。

 下载地址


你可能感兴趣的:(Android,Android达人模仿秀)