滑动菜单方案6:使用PopupWindows实现透明的弹出菜单
2013-12-31 00:55
375 查看
main.xml如下:
styles.xml如下:
popupwindow.xml如下:
in.xml如下:
out.xml如下:
PopupWindowTestActivity.java如下:
查看源码
打印?
<?xmlversion="1.0"encoding="utf-8"?> <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/button" android:text="popupWindow" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RelativeLayout>
styles.xml如下:
1 | <? xml version = "1.0" encoding = "utf-8" ?> |
2 | < resources > |
3 | < style name = "popupAnimation" parent = "android:Animation" > |
4 | < item name = "android:windowEnterAnimation" >@anim/in</ item > |
5 | < item name = "android:windowExitAnimation" >@anim/out</ item > |
6 | </ style > |
7 | </ resources > |
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
02 | < RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
03 | android:layout_width = "match_parent" |
04 | android:layout_height = "match_parent" |
05 | android:background = "#b5555555" > |
06 |
07 | < LinearLayout |
08 | android:layout_width = "match_parent" |
09 | android:layout_height = "wrap_content" |
10 | android:layout_alignParentBottom = "true" |
11 | android:layout_marginBottom = "12dip" |
12 | android:paddingLeft = "10dip" |
13 | android:paddingRight = "10dip" |
14 | android:orientation = "vertical" > |
15 | < Button |
16 | android:id = "@+id/confirmButton" |
17 | android:layout_width = "fill_parent" |
18 | android:layout_height = "wrap_content" |
19 | android:layout_gravity = "center" |
20 | android:text = "确定" /> |
21 |
22 | < Button |
23 | android:id = "@+id/cancleButton" |
24 | android:layout_marginTop = "12dip" |
25 | android:layout_width = "fill_parent" |
26 | android:layout_height = "wrap_content" |
27 | android:layout_gravity = "center" |
28 | android:text = "取消" /> |
29 | </ LinearLayout > |
30 |
31 | </ RelativeLayout > |
1 | <? xml version = "1.0" encoding = "utf-8" ?> |
2 | < set xmlns:android = "http://schemas.android.com/apk/res/android" > |
3 | < translate |
4 | android:fromYDelta = "5000" |
5 | android:toYDelta = "0" |
6 | android:duration = "1500" |
7 | /> |
8 | </ set > |
1 | <? xml version = "1.0" encoding = "utf-8" ?> |
2 | < set xmlns:android = "http://schemas.android.com/apk/res/android" > |
3 | < translate |
4 | android:fromYDelta = "0" |
5 | android:toYDelta = "5000" |
6 | android:duration = "1500" |
7 | /> |
8 | </ set > |
01 | import android.app.Activity; |
02 | import android.graphics.drawable.BitmapDrawable; |
03 | import android.os.Bundle; |
04 | import android.view.Gravity; |
05 | import android.view.LayoutInflater; |
06 | import android.view.View; |
07 | import android.view.View.OnClickListener; |
08 | import android.view.ViewGroup.LayoutParams; |
09 | import android.widget.Button; |
10 | import android.widget.PopupWindow; |
11 | /** |
12 | * Demo描述: |
13 | * 仿Iphone从屏幕底部弹出半透明的PopupWindow |
14 | */ |
15 | public class PopupWindowTestActivity extends Activity { |
16 | private Button button; |
17 | private Button confirmButton; |
18 | private Button cancleButton; |
19 | private PopupWindow popupWindow; |
20 | private View popupWindowView; |
21 | @Override |
22 | public void onCreate(Bundle |
23 | super .onCreate(savedInstanceState); |
24 | setContentView(R.layout.main); |
25 | init(); |
26 | } |
27 | private void init(){ |
28 | button=(Button) findViewById(R.id.button); |
29 | button.setOnClickListener( new ButtonOnClickListener()); |
30 | } |
31 |
32 | private class ButtonOnClickListener implements OnClickListener { |
33 | @Override |
34 | public void onClick(View |
35 | switch (v.getId()) { |
36 | case R.id.button: |
37 | LayoutInflater |
38 | popupWindowView null ); |
39 | popupWindow new PopupWindow(popupWindowView,LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true ); |
40 | popupWindow.setBackgroundDrawable( new BitmapDrawable()); |
41 | //设置PopupWindow的弹出和消失效果 |
42 | popupWindow.setAnimationStyle(R.style.popupAnimation); |
43 | confirmButton |
44 | confirmButton.setOnClickListener( new ButtonOnClickListener()); |
45 | cancleButton |
46 | cancleButton.setOnClickListener( new ButtonOnClickListener()); |
47 | popupWindow.showAtLocation(confirmButton, 0 , 0 ); |
48 | break ; |
49 | case R.id.confirmButton: |
50 | System.out.println( "点击了确定按钮" ); |
51 | break ; |
52 | case R.id.cancleButton: |
53 | popupWindow.dismiss(); |
54 | break ; |
55 | default : |
56 | break ; |
57 | } |
58 |
59 | }} |
60 | } |
相关文章推荐
- 滑动菜单方案之二: Activity实现从底部弹出或滑出选择菜单或窗口
- Android使用属性动画,实现分散式弹出菜单
- 使用PopupWindow实现右上角弹出菜单
- 使用TabLayout、ViewPager和Fragment实现顶部菜单可滑动切换
- Android底部菜单布局+PopupWindows实现弹出菜单功能(初级篇)
- 使用XTablayout实现横向滑动菜单,可以设置文字下面导航栏的宽度
- android中使用PopupWindow实现弹出窗口菜单
- android 使用Scroller实现美团悬浮框,网易左右滑动菜单效果
- 使用TabLayout、ViewPager和Fragment实现顶部菜单可滑动切换
- Android开发技巧——使用PopupWindow实现弹出菜单
- 使用TabLayout、ViewPager和Fragment实现顶部菜单可滑动切换
- Material Design最佳体验(3):使用DrawerLayout、NavigationView轻松实现滑动菜单
- [Android] 底部菜单布局+PopupWindows实现弹出菜单功能(初级篇)
- 使用TabLayout、ViewPager和Fragment实现顶部菜单可滑动切换
- Android开发技巧——使用PopupWindow实现弹出菜单
- Android使用Activity实现从底部弹出菜单或窗口的方法
- 使用FloatingActionButton实现可拖拽动态弹出菜单
- Android 使用PopupWindow实现弹出菜单
- Android Studio 使用ViewPager + Fragment实现滑动菜单Tab效果 --简易版
- 使用CoordinatorLayout实现底部弹出菜单