利用半透明对话框实现新浪微博android客户端首次运行时的提示界面
文章出处:http://blog.csdn.net/sunmanzth/article/details/6902458
首先,设置要覆盖在最上方的dialog的view
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout android:background="@drawable/navigater_bg" android:padding="0.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <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" />
- <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" />
- <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" />
- <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" />
- </RelativeLayout>
然后,在values/styles.xml添加style for 半透明:
- <style name="Dialog_Fullscreen">
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowAnimationStyle">@style/Dialog_Anim</item>
- <item name="android:colorBackgroundCacheHint">@null</item>
- </style>
继续添加style for 淡入淡出效果:
- <style name="Dialog_Anim">
- <item name="android:windowEnterAnimation">@anim/fading_in</item>
- <item name="android:windowExitAnimation">@anim/fading_out</item>
- </style>
在anim文件夹下,添加文件fading_in.xml for 淡入
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" />
- </set>
添加文件fading_out.xml for 淡出
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" />
- </set>
最后,在要弹出对话框的地方添加如下代码:
- Dialog dialog = new Dialog(this, R.style.Dialog_Fullscreen);
- dialog.setContentView(R.layout.sina);
- ImageView iv = (ImageView)dialog.findViewById(R.id.ivNavigater_clickable);
- iv.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- dialog.show();
最终效果如图:
参考:
http://mingkg21.iteye.com/blog/513397