高仿微信界面

来源:互联网 发布:矩阵scalar 编辑:程序博客网 时间:2024/06/05 16:33

在上一篇《是男人就下100层【第一层】——高仿微信界面(6)》中我们已经对主界面的的各个菜单进行了简单实现,接下来我们完成两个比较有趣的功能,一个是上部的下弹式菜单,另一个是摇一摇功能。

效果如下图:


我们先做 一个位于右上方的对话框样子,布局代码很简单,外面是一个相对布局,内部是一个线性布局,布局如下:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.    android:layout_width="fill_parent"  
  4.    android:layout_height="fill_parent"         
  5.    >  
  6.      
  7.    <RelativeLayout  
  8.        android:layout_width="fill_parent"  
  9.        android:layout_height="fill_parent"    
  10.        android:layout_marginTop="46dp"  
  11.          
  12.              >  
  13.           
  14.         <LinearLayout  
  15.             android:id="@+id/main_dialog_layout"  
  16.             android:layout_width="wrap_content"  
  17.             android:layout_height="wrap_content"  
  18.             android:layout_alignParentRight="true"  
  19.             android:layout_alignParentTop="true"  
  20.             android:orientation="vertical"  
  21.             android:background="@drawable/title_function_bg" >  
  22.   
  23.             <LinearLayout  
  24.                 android:layout_width="match_parent"  
  25.                 android:layout_height="wrap_content" >  
  26.   
  27.                 <ImageView  
  28.                     android:id="@+id/imageView1"  
  29.                     android:layout_width="wrap_content"  
  30.                     android:layout_height="wrap_content"  
  31.                     android:layout_gravity="center_vertical"  
  32.                     android:layout_marginLeft="8dp"  
  33.                     android:src="@drawable/mm_title_btn_compose_normal" />  
  34.   
  35.                 <TextView  
  36.                     android:layout_width="wrap_content"  
  37.                     android:layout_height="wrap_content"  
  38.                     android:padding="8dp"  
  39.                     android:text="发起聊天"  
  40.                     android:textColor="#fff"  
  41.                     android:textSize="18sp" />                 
  42.             </LinearLayout>  
  43.             <LinearLayout  
  44.                 android:layout_width="match_parent"  
  45.                 android:layout_height="wrap_content" >  
  46.   
  47.                 <ImageView  
  48.                     android:id="@+id/imageView2"  
  49.                     android:layout_width="wrap_content"  
  50.                     android:layout_height="wrap_content"  
  51.                     android:layout_gravity="center_vertical"  
  52.                     android:layout_marginLeft="8dp"  
  53.                     android:src="@drawable/mm_title_btn_receiver_normal" />  
  54.   
  55.                 <TextView  
  56.                     android:layout_width="wrap_content"  
  57.                     android:layout_height="wrap_content"  
  58.                     android:padding="8dp"  
  59.                     android:text="听筒模式"  
  60.                     android:textColor="#fff"  
  61.                     android:textSize="18sp" />                 
  62.             </LinearLayout>  
  63.             <LinearLayout  
  64.                 android:layout_width="match_parent"  
  65.                 android:layout_height="wrap_content" >  
  66.   
  67.                 <ImageView  
  68.                     android:id="@+id/imageView3"  
  69.                     android:layout_width="wrap_content"  
  70.                     android:layout_height="wrap_content"  
  71.                     android:layout_gravity="center_vertical"  
  72.                     android:layout_marginLeft="8dp"  
  73.                     android:src="@drawable/mm_title_btn_keyboard_normal" />  
  74.   
  75.                 <TextView  
  76.                     android:layout_width="wrap_content"  
  77.                     android:layout_height="wrap_content"  
  78.                     android:padding="8dp"  
  79.                     android:text="登录网页版"  
  80.                     android:textColor="#fff"  
  81.                     android:textSize="18sp" />                 
  82.             </LinearLayout>  
  83.             <LinearLayout  
  84.                 android:layout_width="match_parent"  
  85.                 android:layout_height="wrap_content" >  
  86.   
  87.                 <ImageView  
  88.                     android:id="@+id/imageView4"  
  89.                     android:layout_width="wrap_content"  
  90.                     android:layout_height="wrap_content"  
  91.                     android:layout_gravity="center_vertical"  
  92.                     android:layout_marginLeft="8dp"  
  93.                     android:src="@drawable/mm_title_btn_qrcode_normal" />  
  94.   
  95.                 <TextView  
  96.                     android:layout_width="wrap_content"  
  97.                     android:layout_height="wrap_content"  
  98.                     android:padding="8dp"  
  99.                     android:text="扫一扫"  
  100.                     android:textColor="#fff"  
  101.                     android:textSize="18sp" />                 
  102.             </LinearLayout>  
  103.   
  104.           
  105.              
  106.        </LinearLayout>  
  107.   
  108.     </RelativeLayout>  
  109. </RelativeLayout>  
效果:


这个背景是黑色是因为主题的原因,既然和主题有个那么我们能不能修改主题使背景透明呢,答案是可行的。

自定义主题样式(有关自定义主题请看我的另外一篇博文:http://blog.csdn.net/dawanganban/article/details/17732701)

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <style name="MyDialogStyleTop" parent="android:Theme.Dialog" >  
  2.     <item name="android:windowAnimationStyle">@style/AnimTop2</item>  
  3.     <item name="android:windowFrame">@null</item><!--边框-->  
  4.     <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->  
  5.     <item name="android:windowIsTranslucent">true</item><!--半透明-->  
  6.     <item name="android:windowNoTitle">true</item><!--无标题-->  
  7.     <item name="android:windowBackground">@android:color/transparent</item><!--背景透明-->  
  8.     <item name="android:backgroundDimEnabled">false</item><!--模糊-->          
  9.  </style>  
切换动画

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <style name="AnimTop2" parent="@android:style/Animation">    
  2.     <item name="android:windowEnterAnimation">@anim/push_top_in2</item>  
  3.     <item name="android:windowExitAnimation">@anim/push_top_out2</item>  
  4. </style>  
[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!-- 上下滑入式 -->  
  3. <scale   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.         android:interpolator="@android:anim/accelerate_decelerate_interpolator"    
  5.         android:fromXScale="1.0"     
  6.         android:toXScale="1.0"     
  7.         android:fromYScale="0"     
  8.         android:toYScale="1.0"     
  9.         android:pivotX="0"    
  10.         android:pivotY="10%"    
  11.         android:duration="200" />   
[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <scale   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.         android:interpolator="@android:anim/accelerate_decelerate_interpolator"    
  5.         android:fromXScale="1.0"     
  6.         android:toXScale="1.0"     
  7.         android:fromYScale="1.0"     
  8.         android:toYScale="0"     
  9.         android:pivotX="0"    
  10.         android:pivotY="10%"    
  11.         android:duration="200" />   

给该Activity设置主题

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <activity android:name="com.example.weixin.activity.MainTopRightDialog" android:theme="@style/MyDialogStyleTop">  
  2.       
  3. </activity>  

设置主题样式后的运行结果和第一个图相同,这里就不贴图了,运行后 如何让这个菜单消失,这就需要重写onTouchEvent了,Activity内的代码如下:

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. package com.example.weixin.activity;  
  2.   
  3.   
  4. import android.app.Activity;  
  5. import android.os.Bundle;  
  6. import android.view.MotionEvent;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.widget.LinearLayout;  
  10. import android.widget.Toast;  
  11.   
  12. import com.example.weixin.R;  
  13.   
  14. public class MainTopRightDialog extends Activity {  
  15.     //private MyDialog dialog;  
  16.     private LinearLayout layout;  
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.main_top_right_dialog);  
  21.         //dialog=new MyDialog(this);  
  22.         layout=(LinearLayout)findViewById(R.id.main_dialog_layout);  
  23.         layout.setOnClickListener(new OnClickListener() {  
  24.               
  25.             @Override  
  26.             public void onClick(View v) {  
  27.                 // TODO Auto-generated method stub  
  28.                 Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",   
  29.                         Toast.LENGTH_SHORT).show();   
  30.             }  
  31.         });  
  32.     }  
  33.   
  34.     @Override  
  35.     public boolean onTouchEvent(MotionEvent event){  
  36.         finish();  
  37.         return true;  
  38.     }  
  39. }  
这样就实现了上面的下弹式菜单了,呵呵。


下一篇我们来看一下如何实现摇一摇功能,不仅仅是实现,而是要实现的和微信上面的一模一样(代码下一篇中贴出)。

0 0
原创粉丝点击