Skip to content

Commit

Permalink
增加ddmenuMenuHeightPercent设置菜单的最大高度
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjunkun committed Apr 11, 2017
1 parent ade932c commit 63e308f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ allprojects {
}
dependencies {
compile 'com.github.dongjunkun:DropDownMenu:1.0.3'
compile 'com.github.dongjunkun:DropDownMenu:1.0.4'
}
```

Expand All @@ -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" 菜单的最大高度,根据屏幕高度的百分比设置
...
/>
```
Expand Down
8 changes: 8 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
49 changes: 49 additions & 0 deletions library/src/main/java/com/yyydjk/library/DeviceUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2013 Peng fei Pan <sky@xiaopan.me>
*
* 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;
}
}


}
4 changes: 4 additions & 0 deletions library/src/main/java/com/yyydjk/library/DropDownMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<attr name="ddmenuTextSize" format="dimension"/>
<attr name="ddmenuSelectedIcon" format="reference"/>
<attr name="ddmenuUnselectedIcon" format="reference"/>
<attr name="ddmenuMenuHeightPercent" format="float"/>
</declare-styleable>
</resources>

0 comments on commit 63e308f

Please sign in to comment.