Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对DropDownMenu做了扩展 #28

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f06bfd8
对库的tabView的样式做了扩展
keyboard3 Oct 14, 2016
297f496
扩展了库的tabMenuView任意位置插入自定义的tabView
keyboard3 Oct 14, 2016
929fd6a
细节完善
keyboard3 Oct 14, 2016
9b17dae
稍作完善,添加的tabView,不会被自动加上箭头
keyboard3 Oct 15, 2016
be6455d
对添加按钮加了关闭菜单,完善演示
keyboard3 Oct 15, 2016
f9048cb
Update README.md
keyboard3 Oct 15, 2016
9405c91
Update README.md
keyboard3 Oct 15, 2016
e503a72
Update README.md
keyboard3 Oct 15, 2016
2152426
Update README.md
keyboard3 Oct 15, 2016
425e1d6
应读者的要求加了一个控制箭头坐在位置方向的位置的属性
keyboard3 Oct 26, 2016
ed8cd7a
Merge branch 'master' of https://github.com/keyboard3/DropDownMenu
keyboard3 Oct 26, 2016
c26b4db
应读者要求加了箭头在文本的方向属性
keyboard3 Oct 26, 2016
693f867
Update README.md
keyboard3 Oct 26, 2016
3926608
添加了可以控制分隔线的高度的属性
keyboard3 Jan 3, 2017
b532f9c
Merge branch 'master' of https://github.com/keyboard3/DropDownMenu
keyboard3 Jan 3, 2017
4fe3f75
Update README.md
keyboard3 Jan 3, 2017
8b86b9d
Update README.md
keyboard3 Jan 3, 2017
ad220cf
Update README.md
keyboard3 Jan 3, 2017
35986e1
添加popupWindows集合中view的LayoutParams支持
keyboard3 Jan 5, 2017
9a167a8
Update README.md
keyboard3 Jan 5, 2017
7966e11
tab扩展添加到末尾的Bug
keyboard3 Mar 22, 2017
0f44ee5
修复箭头无法更换的问题
keyboard3 Jul 20, 2017
2ae0ab8
新增menu tab切换回调接口
keyboard3 Jul 21, 2017
87fd222
修改了初始化图标问题
keyboard3 Sep 8, 2017
8b61c35
Update README.md
keyboard3 Dec 3, 2017
a366331
Update README.md
keyboard3 Dec 3, 2017
3b8fa0c
Update README.md
keyboard3 Dec 3, 2017
02068eb
Update README.md
keyboard3 Dec 3, 2017
420587f
Update README.md
keyboard3 Dec 3, 2017
5e89c18
修复了7.0占满屏的问题
keyboard3 Dec 14, 2017
24e1d8b
demo apk上传
keyboard3 Dec 14, 2017
a0e823c
Merge remote-tracking branch 'origin/master'
keyboard3 Dec 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DropDownMenu.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
138 changes: 88 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,103 @@
[![](https://jitpack.io/v/dongjunkun/DropDownMenu.svg)](https://jitpack.io/#dongjunkun/DropDownMenu)

## 简介
一个实用的多条件筛选菜单,在很多App上都能看到这个效果,如美团,爱奇艺电影票等
扩展的思路 可以看我的[简书](http://www.jianshu.com/p/719267a0df32)

我的博客 [自己造轮子--android常用多条件帅选菜单实现思路(类似美团,爱奇艺电影票下拉菜单)](http://www.jianshu.com/p/d9407f799d2d)
## 下载
[demo.apk](app/build/outputs/apk/app-debug.apk)

##特色
- 支持多级菜单
- 你可以完全自定义你的菜单样式,我这里只是封装了一些实用的方法,Tab的切换效果,菜单显示隐藏效果等
- 并非用popupWindow实现,无卡顿
## 特色
* 支持多级菜单
* 你可以完全自定义你的菜单样式,我这里只是封装了一些实用的方法,Tab的切换效果,菜单显示隐藏效果等
* 非用popupWindow实现,无卡顿

## 截图
<div style="display:inline;"><img src="dropdown_demo.gif" width="332"></div>

##ScreenShot
<img src="https://raw.githubusercontent.com/dongjunkun/DropDownMenu/master/art/simple.gif"/>
## 扩展

<a href="https://raw.githubusercontent.com/dongjunkun/DropDownMenu/master/app/build/outputs/apk/app-debug.apk">Download APK</a>
箭头居中而不是居最右<br>
<img src="http://upload-images.jianshu.io/upload_images/1682632-a7d108a623dabb17.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">

或者扫描二维码
icon方向属性<br>
<img src="http://upload-images.jianshu.io/upload_images/1682632-67fed77c933c62c8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">
<img src="http://upload-images.jianshu.io/upload_images/1682632-a9830a6500806c6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">

<img src="https://raw.githubusercontent.com/dongjunkun/DropDownMenu/master/art/download.png"/>
分隔线高度属性<br>
<img src="http://upload-images.jianshu.io/upload_images/1682632-14683c5a45292208.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">
<img src="http://upload-images.jianshu.io/upload_images/1682632-74b76c2474762382.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">

##Gradle Dependency
为popupWindows集合的view增加了对LayoutParams的支持<br>
<img src="http://upload-images.jianshu.io/upload_images/1682632-e65f5c4edefc1b1e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="700">
<img src="http://upload-images.jianshu.io/upload_images/1682632-86ef98adaf6c8d44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">

```
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
支持手动添加非下拉tabView<br>
<img src="http://upload-images.jianshu.io/upload_images/1682632-54018e2db4c6bc13.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" width="350">

dependencies {
compile 'com.github.dongjunkun:DropDownMenu:1.0.3'
}
```
## 使用
注意:`此布局需要作为根布局才可能覆盖内容区域`

##使用
添加DropDownMenu 到你的布局文件,如下
* 样式扩展
添加名为tab_item.xml到你的布局文件,在要显示内容的TextView上设置id为R.id.tv_tab。tab_item.xml中 任意布局即可。<br>
tab_item.xml
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/tv_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="7dp"
android:gravity="center"
android:paddingBottom="12dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="12dp"
android:textColor="#26a8e0" />
</LinearLayout>
```
<com.yyydjk.library.DropDownMenu
android:id="@+id/dropDownMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ddmenuTextSize="13sp" //tab字体大小
app:ddtextUnselectedColor="@color/drop_down_unselected" //tab未选中颜色
app:ddtextSelectedColor="@color/drop_down_selected" //tab选中颜色
app:dddividerColor="@color/gray" //分割线颜色
app:ddunderlineColor="@color/gray" //下划线颜色
app:ddmenuSelectedIcon="@mipmap/drop_down_selected_icon" //tab选中状态图标
app:ddmenuUnselectedIcon="@mipmap/drop_down_unselected_icon"//tab未选中状态图标
app:ddmaskColor="@color/mask_color" //遮罩颜色,一般是半透明
app:ddmenuBackgroundColor="@color/white" //tab 背景颜色
...
/>
```
我们只需要在java代码中调用下面的代码

* 手动添加非下拉tabView
tab_text.xml设置样式/也可以代码生成,加载控件添加到DropDownMenu中<br>
tab_text
```xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="7dp"
android:gravity="center"
android:paddingBottom="12dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="12dp"
android:textColor="#26a8e0"
xmlns:android="http://schemas.android.com/apk/res/android" />
```
//tabs 所有标题,popupViews 所有菜单,contentView 内容
mDropDownMenu.setDropDownMenu(tabs, popupViews, contentView);
调用添加,在setDropDownMenu之后添加
```java
...
//init dropdownview
mDropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, contentView);
//测试tabView扩展功能
TextView textView= (TextView) getLayoutInflater().inflate(R.layout.tab_text,null);
textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
textView.setText("所有");
mDropDownMenu.addTab(textView,0);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDropDownMenu.closeMenu();
}
});
```
如果你要了解更多,可以直接看源码 <a href="https://github.com/dongjunkun/DropDownMenu/blob/master/app/src/main/java/com/yyy/djk/dropdownmenu/MainActivity.java">Example</a>

##关于我
简书[dongjunkun](http://www.jianshu.com/users/f07458c1a8f3/latest_articles)
如果你要了解更多,可以直接看源码 <a href="https://github.com/keyboard3/DropDownMenu/blob/master/app/src/main/java/com/yyy/djk/dropdownmenu/MainActivity.java">Example</a>

## 关于我

简书 [keyboard3](http://www.jianshu.com/users/62329de8c8a6/latest_articles)<br>
邮箱 keyboard3@icloud.com

# 致谢

- 感谢 [dongjunkun/DropDownMenu](https://github.com/dongjunkun/DropDownMenu)
16 changes: 8 additions & 8 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" 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" />
Expand Down
Binary file modified app/build/outputs/apk/app-debug.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:fullBackupContent="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
Expand Down
40 changes: 37 additions & 3 deletions app/src/main/java/com/yyy/djk/dropdownmenu/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

Expand All @@ -22,7 +24,8 @@

public class MainActivity extends AppCompatActivity {

@InjectView(R.id.dropDownMenu) DropDownMenu mDropDownMenu;
@InjectView(R.id.dropDownMenu)
DropDownMenu mDropDownMenu;
private String headers[] = {"城市", "年龄", "性别", "星座"};
private List<View> popupViews = new ArrayList<>();

Expand All @@ -47,6 +50,12 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void initView() {
//测试tabView扩展功能
final TextView textView = (TextView) getLayoutInflater().inflate(R.layout.tab_text, null);
textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
textView.setTextColor(getResources().getColor(R.color.drop_down_selected));
textView.setText("所有");

//init city menu
final ListView cityView = new ListView(this);
cityAdapter = new GirdDropDownAdapter(this, Arrays.asList(citys));
Expand Down Expand Up @@ -78,7 +87,11 @@ public void onClick(View v) {
mDropDownMenu.closeMenu();
}
});

//添加时间 2017年1月5日21:28:22
//keyboard3 为支持可以外部控制popViews里的View可以设置layoutParams。注意必须是FrameLayout的布局参数
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(200, 100, 200, 0);
cityView.setLayoutParams(layoutParams);
//init popupViews
popupViews.add(cityView);
popupViews.add(ageView);
Expand All @@ -92,6 +105,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
cityAdapter.setCheckItem(position);
mDropDownMenu.setTabText(position == 0 ? headers[0] : citys[position]);
mDropDownMenu.closeMenu();
textView.setTextColor(getResources().getColor(R.color.drop_down_unselected));
}
});

Expand All @@ -101,6 +115,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
ageAdapter.setCheckItem(position);
mDropDownMenu.setTabText(position == 0 ? headers[1] : ages[position]);
mDropDownMenu.closeMenu();
textView.setTextColor(getResources().getColor(R.color.drop_down_unselected));
}
});

Expand All @@ -110,6 +125,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
sexAdapter.setCheckItem(position);
mDropDownMenu.setTabText(position == 0 ? headers[2] : sexs[position]);
mDropDownMenu.closeMenu();
textView.setTextColor(getResources().getColor(R.color.drop_down_unselected));
}
});

Expand All @@ -128,8 +144,26 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
contentView.setGravity(Gravity.CENTER);
contentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);

//init dropdownview
//初始化 dropdownview
mDropDownMenu.setDropDownMenu(Arrays.asList(headers), popupViews, contentView);
mDropDownMenu.addTab(textView, 4);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mDropDownMenu.isActive()) {
mDropDownMenu.closeMenu();
textView.setTextColor(getResources().getColor(R.color.drop_down_selected));
} else {
textView.setTextColor(getResources().getColor(R.color.drop_down_unselected));
}
}
});
mDropDownMenu.setOnItemMenuClickListener(new DropDownMenu.OnItemMenuClickListener() {
@Override
public void OnItemMenuClick(TextView tabView, int position) {
textView.setTextColor(getResources().getColor(R.color.drop_down_unselected));
}
});
}

@Override
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<com.yyydjk.library.DropDownMenu
android:id="@+id/dropDownMenu"
<com.yyydjk.library.DropDownMenu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dropDownMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ddmenuTextSize="13sp"
app:ddtextUnselectedColor="@color/drop_down_unselected"
app:ddtextSelectedColor="@color/drop_down_selected"
app:dddividerColor="@color/gray"
app:ddunderlineColor="@color/gray"
app:ddmenuSelectedIcon="@mipmap/drop_down_selected_icon"
app:ddmaskColor="@color/mask_color"
app:ddmenuBackgroundColor="@color/white"
app:ddmenuIconOrientation="left"
app:ddmenuSelectedIcon="@mipmap/drop_down_selected_icon"
app:ddmenuTextSize="13sp"
app:ddmenuUnselectedIcon="@mipmap/drop_down_unselected_icon"
/>
app:ddtextSelectedColor="@color/drop_down_selected"
app:ddtextUnselectedColor="@color/drop_down_unselected"
app:ddunderlineColor="@color/gray"></com.yyydjk.library.DropDownMenu>
1 change: 0 additions & 1 deletion app/src/main/res/layout/custom_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<GridView
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/item_default_drop_down.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<TextView
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/tab_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="7dp"
android:gravity="center"
android:paddingBottom="12dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="12dp"
android:textColor="#26a8e0"
xmlns:android="http://schemas.android.com/apk/res/android" />
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<resources>
<string name="app_name">DropDownMenu</string>

<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Binary file added dropdown_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-24.2.1" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-24.2.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-24.2.1" level="project" />
</component>
</module>
Loading