diff --git a/DropDownMenu.iml b/DropDownMenu.iml index a164e72..6981f2b 100644 --- a/DropDownMenu.iml +++ b/DropDownMenu.iml @@ -13,7 +13,7 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index 3ba1093..0413c5d 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ 我的博客 [自己造轮子--android常用多条件帅选菜单实现思路(类似美团,爱奇艺电影票下拉菜单)](http://www.jianshu.com/p/d9407f799d2d) -##特色 +## 特色 - 支持多级菜单 - 你可以完全自定义你的菜单样式,我这里只是封装了一些实用的方法,Tab的切换效果,菜单显示隐藏效果等 - 并非用popupWindow实现,无卡顿 -##ScreenShot +## ScreenShot Download APK @@ -19,7 +19,7 @@ -##Gradle Dependency +## Gradle Dependency ``` allprojects { @@ -30,11 +30,11 @@ allprojects { } dependencies { - compile 'com.github.dongjunkun:DropDownMenu:1.0.3' + compile 'com.github.dongjunkun:DropDownMenu:1.0.4' } ``` -##使用 +## 使用 添加DropDownMenu 到你的布局文件,如下 ``` ``` @@ -61,5 +62,7 @@ mDropDownMenu.setDropDownMenu(tabs, popupViews, contentView); ``` 如果你要了解更多,可以直接看源码 Example -##关于我 +> 建议拷贝代码到项目中使用,拷贝DropDownMenu.java 以及res下的所有文件即可 + +## 关于我 简书[dongjunkun](http://www.jianshu.com/users/f07458c1a8f3/latest_articles) diff --git a/app/app.iml b/app/app.iml index 69b9701..e994da9 100644 --- a/app/app.iml +++ b/app/app.iml @@ -9,13 +9,9 @@ + + + @@ -48,44 +47,66 @@ - + + + + + + + + - + - + + + + + + + + - - + + - + - - + - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index e727623..f62c792 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,11 +1,2 @@ - - - - - - + diff --git a/library/src/main/java/com/yyydjk/library/DeviceUtils.java b/library/src/main/java/com/yyydjk/library/DeviceUtils.java new file mode 100644 index 0000000..cd221da --- /dev/null +++ b/library/src/main/java/com/yyydjk/library/DeviceUtils.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013 Peng fei Pan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.yyydjk.library; + +import android.annotation.TargetApi; +import android.content.Context; +import android.graphics.Point; +import android.os.Build; +import android.view.Display; +import android.view.WindowManager; + +/** + * 设备工具箱,提供与设备硬件相关的工具方法 + */ +public class DeviceUtils { + + /** + * 获取屏幕尺寸 + */ + @SuppressWarnings("deprecation") + @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) + public static Point getScreenSize(Context context){ + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + Display display = windowManager.getDefaultDisplay(); + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2){ + return new Point(display.getWidth(), display.getHeight()); + }else{ + Point point = new Point(); + display.getSize(point); + return point; + } + } + + +} \ No newline at end of file diff --git a/library/src/main/java/com/yyydjk/library/DropDownMenu.java b/library/src/main/java/com/yyydjk/library/DropDownMenu.java index 92f8480..fa3a8f2 100644 --- a/library/src/main/java/com/yyydjk/library/DropDownMenu.java +++ b/library/src/main/java/com/yyydjk/library/DropDownMenu.java @@ -50,6 +50,8 @@ public class DropDownMenu extends LinearLayout { //tab未选中图标 private int menuUnselectedIcon; + private float menuHeighPercent = 0.5f; + public DropDownMenu(Context context) { super(context, null); @@ -77,6 +79,7 @@ public DropDownMenu(Context context, AttributeSet attrs, int defStyleAttr) { menuTextSize = a.getDimensionPixelSize(R.styleable.DropDownMenu_ddmenuTextSize, menuTextSize); menuSelectedIcon = a.getResourceId(R.styleable.DropDownMenu_ddmenuSelectedIcon, menuSelectedIcon); menuUnselectedIcon = a.getResourceId(R.styleable.DropDownMenu_ddmenuUnselectedIcon, menuUnselectedIcon); + menuHeighPercent = a.getFloat(R.styleable.DropDownMenu_ddmenuMenuHeightPercent,menuHeighPercent); a.recycle(); //初始化tabMenuView并添加到tabMenuView @@ -128,8 +131,12 @@ public void onClick(View v) { }); containerView.addView(maskView, 1); maskView.setVisibility(GONE); + if (containerView.getChildAt(2) != null){ + containerView.removeViewAt(2); + } popupMenuViews = new FrameLayout(getContext()); + popupMenuViews.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (DeviceUtils.getScreenSize(getContext()).y*menuHeighPercent))); popupMenuViews.setVisibility(GONE); containerView.addView(popupMenuViews, 2); diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index cf5bf47..cf25ade 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -11,5 +11,6 @@ + \ No newline at end of file diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml deleted file mode 100644 index 6d51856..0000000 --- a/library/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Library -