一个activity悬浮在另一个activity上,背景透明化效果

在anim文件中新建两个xml文件
push_bottom_in.xml
< set xmlns: android = "http://schemas.android.com/apk/res/android" >
< translate
android :duration= "200"
android :fromYDelta= "50%p"
android :toYDelta= "0" />
set >

push_bottom_out.xml

< set xmlns: android = "http://schemas.android.com/apk/res/android" >
< translate
android :duration= "200"
android :fromYDelta= "0"
android :toYDelta= "50%p" />
set >
在values文件夹中的styles中定义效果样式
< style name= "AnimBottom" parent= "@android:style/Animation" >
< item name= "android:windowEnterAnimation" >@anim/push_bottom_in item >
< item name= "android:windowExitAnimation" >@anim/push_bottom_out item >
style >
< style name= "MyDialogStyleBottom" parent= "android:Theme.Dialog" >
< item name= "android:windowAnimationStyle" >@style/AnimBottom item >
< item name= "android:windowFrame" >@null item >
< item name= "android:windowIsFloating" >true item >
< item name= "android:windowIsTranslucent" >true item >
< item name= "android:windowNoTitle" >true item >
< item name= "android:windowBackground" >@android:color/transparent item >
< item name= "android:backgroundDimEnabled" >true item >
style >

注意:在定义的类只能继承Activity (否则会闪退)
在代码中需要加上一段代码使其充满整个屏幕
getWindow().setLayout(ActionBar.LayoutParams. MATCH_PARENT , ActionBar.LayoutParams. MATCH_PARENT );

最后在Layout该布局中引用
< RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android :layout_width= "match_parent"
android :layout_height= "match_parent"
android :orientation= "vertical" >
< LinearLayout
android :layout_width= "match_parent"
android :layout_height= "match_parent"
android :gravity= "center_horizontal" >
< LinearLayout
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
android :gravity= "center_horizontal"
android :layout_gravity= "bottom"
android :orientation= "vertical" >
< RelativeLayout
android :layout_width= "fill_parent"
android :layout_height= "65dp"
android :gravity= "center_horizontal"
android :background= "@color/lan" >
< TextView
android :layout_width= "wrap_content"
android :layout_height= "wrap_content"
android :textColor= "@color/bai"
android :textSize= "17.0sp"
android :layout_centerHorizontal= "true"
android :layout_centerVertical= "true"
android :text= "账户选择" />
RelativeLayout >
< ListView
android :id= "@+id/lv_zhifufangshi"
android :layout_width= "fill_parent"
android :layout_height= "wrap_content"
android :background= "@color/bai"
android :divider= "@null"
android :fadingEdge= "none"
android :listSelector= "@android:color/transparent"
android :scrollbars= "none" >
ListView >
LinearLayout >
LinearLayout >
RelativeLayout >


你可能感兴趣的:(一个activity悬浮在另一个activity上,背景透明化效果)