利用半透明对话框实现新浪微博android客户端首次运行时的提示界面

文章出处:http://blog.csdn.net/sunmanzth/article/details/6902458


 

首先,设置要覆盖在最上方的dialog的view

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout android:background="@drawable/navigater_bg" android:padding="0.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent"  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <ImageView android:id="@id/ivNavigater_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/navigater_top" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" />  
  5.     <ImageView android:id="@id/ivNavigater_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/navigater_center" android:layout_centerInParent="true" />  
  6.     <ImageView android:id="@id/ivNavigater_clickable" android:padding="0.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0.0dip" android:src="@drawable/navigater_clickable" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" />  
  7.     <ImageView android:id="@id/ivNavigater_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0.0dip" android:src="@drawable/navigater_bottom" android:adjustViewBounds="true" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" />  
  8. </RelativeLayout>  


然后,在values/styles.xml添加style for 半透明:

[html] view plaincopy
 
  1. <style name="Dialog_Fullscreen">  
  2.     <item name="android:windowBackground">@android:color/transparent</item>  
  3.     <item name="android:windowNoTitle">true</item>  
  4.     <item name="android:windowIsTranslucent">true</item>  
  5.     <item name="android:windowContentOverlay">@null</item>  
  6.     <item name="android:windowAnimationStyle">@style/Dialog_Anim</item>  
  7.     <item name="android:colorBackgroundCacheHint">@null</item>  
  8. </style>  


继续添加style for 淡入淡出效果:

[html] view plaincopy
 
  1. <style name="Dialog_Anim">  
  2.     <item name="android:windowEnterAnimation">@anim/fading_in</item>  
  3.     <item name="android:windowExitAnimation">@anim/fading_out</item>  
  4. </style>  

在anim文件夹下,添加文件fading_in.xml for 淡入

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" />  
  5. </set>  


添加文件fading_out.xml for 淡出

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <set  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" />  
  5. </set>  


最后,在要弹出对话框的地方添加如下代码:

[java] view plaincopy
 
  1.       Dialog dialog = new Dialog(this, R.style.Dialog_Fullscreen);          
  2.       dialog.setContentView(R.layout.sina);  
  3.       ImageView iv = (ImageView)dialog.findViewById(R.id.ivNavigater_clickable);  
  4.       iv.setOnClickListener(new OnClickListener() {  
  5.       
  6.     @Override  
  7.     public void onClick(View v) {  
  8.         dialog.dismiss();  
  9.     }  
  10. });  
  11.       dialog.show();  



最终效果如图:


参考:

          http://mingkg21.iteye.com/blog/513397

posted on 2012-09-06 12:17  jiezzy  阅读(838)  评论(0编辑  收藏  举报