From 63e308f94282fa23e4a8c043328033913c88214d Mon Sep 17 00:00:00 2001 From: dongjunkun <1440418246@qq.com> Date: Tue, 11 Apr 2017 16:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ddmenuMenuHeightPercent?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=8F=9C=E5=8D=95=E7=9A=84=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- app/app.iml | 8 +++ app/src/main/res/layout/activity_main.xml | 1 + library/library.iml | 6 +++ .../java/com/yyydjk/library/DeviceUtils.java | 49 +++++++++++++++++++ .../java/com/yyydjk/library/DropDownMenu.java | 4 ++ library/src/main/res/values/attrs.xml | 1 + 7 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/yyydjk/library/DeviceUtils.java diff --git a/README.md b/README.md index 47fa0f0..0413c5d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ allprojects { } dependencies { - compile 'com.github.dongjunkun:DropDownMenu:1.0.3' + compile 'com.github.dongjunkun:DropDownMenu:1.0.4' } ``` @@ -50,6 +50,7 @@ dependencies { app:ddmenuUnselectedIcon="@mipmap/drop_down_unselected_icon"//tab未选中状态图标 app:ddmaskColor="@color/mask_color" //遮罩颜色,一般是半透明 app:ddmenuBackgroundColor="@color/white" //tab 背景颜色 + app:ddmenuMenuHeightPercent="0.5" 菜单的最大高度,根据屏幕高度的百分比设置 ... /> ``` diff --git a/app/app.iml b/app/app.iml index 2988082..e994da9 100644 --- a/app/app.iml +++ b/app/app.iml @@ -76,13 +76,21 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 200eb11..3493ce9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -9,6 +9,7 @@ app:ddtextSelectedColor="@color/drop_down_selected" app:dddividerColor="@color/gray" app:ddunderlineColor="@color/gray" + app:ddmenuMenuHeightPercent="0.5" app:ddmenuSelectedIcon="@mipmap/drop_down_selected_icon" app:ddmaskColor="@color/mask_color" app:ddmenuBackgroundColor="@color/white" diff --git a/library/library.iml b/library/library.iml index c22369d..8936acf 100644 --- a/library/library.iml +++ b/library/library.iml @@ -77,16 +77,22 @@ + + + + + + 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 5c86a34..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 @@ -133,6 +136,7 @@ public void onClick(View v) { } 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