Skip to content

Commit 63e308f

Browse files
committed
增加ddmenuMenuHeightPercent设置菜单的最大高度
1 parent ade932c commit 63e308f

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ allprojects {
3030
}
3131
3232
dependencies {
33-
compile 'com.github.dongjunkun:DropDownMenu:1.0.3'
33+
compile 'com.github.dongjunkun:DropDownMenu:1.0.4'
3434
}
3535
```
3636

@@ -50,6 +50,7 @@ dependencies {
5050
app:ddmenuUnselectedIcon="@mipmap/drop_down_unselected_icon"//tab未选中状态图标
5151
app:ddmaskColor="@color/mask_color" //遮罩颜色,一般是半透明
5252
app:ddmenuBackgroundColor="@color/white" //tab 背景颜色
53+
app:ddmenuMenuHeightPercent="0.5" 菜单的最大高度,根据屏幕高度的百分比设置
5354
...
5455
/>
5556
```

app/app.iml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,21 @@
7676
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
7777
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
7878
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
7980
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
8082
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
8185
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
8287
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8388
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
8490
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
91+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
8592
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
93+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8694
</content>
8795
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
8896
<orderEntry type="sourceFolder" forTests="false" />

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
app:ddtextSelectedColor="@color/drop_down_selected"
1010
app:dddividerColor="@color/gray"
1111
app:ddunderlineColor="@color/gray"
12+
app:ddmenuMenuHeightPercent="0.5"
1213
app:ddmenuSelectedIcon="@mipmap/drop_down_selected_icon"
1314
app:ddmaskColor="@color/mask_color"
1415
app:ddmenuBackgroundColor="@color/white"

library/library.iml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,22 @@
7777
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
7878
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
7979
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
8081
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
8182
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
8284
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
8387
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
8488
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
8589
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8690
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8791
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
8892
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
93+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
8994
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
95+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
9096
</content>
9197
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
9298
<orderEntry type="sourceFolder" forTests="false" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2013 Peng fei Pan <[email protected]>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.yyydjk.library;
18+
19+
import android.annotation.TargetApi;
20+
import android.content.Context;
21+
import android.graphics.Point;
22+
import android.os.Build;
23+
import android.view.Display;
24+
import android.view.WindowManager;
25+
26+
/**
27+
* 设备工具箱,提供与设备硬件相关的工具方法
28+
*/
29+
public class DeviceUtils {
30+
31+
/**
32+
* 获取屏幕尺寸
33+
*/
34+
@SuppressWarnings("deprecation")
35+
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
36+
public static Point getScreenSize(Context context){
37+
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
38+
Display display = windowManager.getDefaultDisplay();
39+
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2){
40+
return new Point(display.getWidth(), display.getHeight());
41+
}else{
42+
Point point = new Point();
43+
display.getSize(point);
44+
return point;
45+
}
46+
}
47+
48+
49+
}

library/src/main/java/com/yyydjk/library/DropDownMenu.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class DropDownMenu extends LinearLayout {
5050
//tab未选中图标
5151
private int menuUnselectedIcon;
5252

53+
private float menuHeighPercent = 0.5f;
54+
5355

5456
public DropDownMenu(Context context) {
5557
super(context, null);
@@ -77,6 +79,7 @@ public DropDownMenu(Context context, AttributeSet attrs, int defStyleAttr) {
7779
menuTextSize = a.getDimensionPixelSize(R.styleable.DropDownMenu_ddmenuTextSize, menuTextSize);
7880
menuSelectedIcon = a.getResourceId(R.styleable.DropDownMenu_ddmenuSelectedIcon, menuSelectedIcon);
7981
menuUnselectedIcon = a.getResourceId(R.styleable.DropDownMenu_ddmenuUnselectedIcon, menuUnselectedIcon);
82+
menuHeighPercent = a.getFloat(R.styleable.DropDownMenu_ddmenuMenuHeightPercent,menuHeighPercent);
8083
a.recycle();
8184

8285
//初始化tabMenuView并添加到tabMenuView
@@ -133,6 +136,7 @@ public void onClick(View v) {
133136
}
134137

135138
popupMenuViews = new FrameLayout(getContext());
139+
popupMenuViews.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (DeviceUtils.getScreenSize(getContext()).y*menuHeighPercent)));
136140
popupMenuViews.setVisibility(GONE);
137141
containerView.addView(popupMenuViews, 2);
138142

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<attr name="ddmenuTextSize" format="dimension"/>
1212
<attr name="ddmenuSelectedIcon" format="reference"/>
1313
<attr name="ddmenuUnselectedIcon" format="reference"/>
14+
<attr name="ddmenuMenuHeightPercent" format="float"/>
1415
</declare-styleable>
1516
</resources>

0 commit comments

Comments
 (0)