DropDownView
介绍:
一个漂亮的下拉视图,自带箭头动画。
运行效果:
使用说明:
确保 minSdkVersion在 19 或者以上:
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.anthonyfdev.dropdownviewexample"
minSdkVersion 19
targetSdkVersion 25
}
}
在根 build.gradle中添加jitpack仓库:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
在app的build.gradle中添加依赖:
dependencies {
compile 'com.github.AnthonyFermin:DropDownView:1.0.1'
}
xml:
<com.anthonyfdev.dropdownview.DropDownView
android:id="@+id/drop_down_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:containerBackgroundColor="#b71c1c"
app:overlayColor="#64000000"/>
注:containerBackgroundColor默认为colorPrimary(如果没有定义就是#3F51B5),overlayColor默认为#99000000(60% 透明度)。
Bind views:
dropDownView = (DropDownView) findViewById(R.id.drop_down_view);
collapsedView = LayoutInflater.from(this).inflate(R.layout.view_my_drop_down_header, null, false);
expandedView = LayoutInflater.from(this).inflate(R.layout.view_my_drop_down_expanded, null, false);
设置DropDownView的 header 和 expanded view:
dropDownView.setHeaderView(collapsedView);
dropDownView.setExpandedView(expandedView);
调用 expand 或者 collapse:
collapsedView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dropDownView.isExpanded()) {
dropDownView.collapseDropDown();
} else {
dropDownView.expandDropDown();
}
}
});
Optional DropDownListener:
/**
* A listener that wraps functionality to be performed when the drop down is successfully expanded
* or collapsed.
*/
private final DropDownView.DropDownListener dropDownListener = new DropDownView.DropDownListener() {
@Override
public void onExpandDropDown() {
adapter.notifyDataSetChanged();
ObjectAnimator.ofFloat(headerChevronIV, View.ROTATION.getName(), 180).start();
}
@Override
public void onCollapseDropDown() {
ObjectAnimator.ofFloat(headerChevronIV, View.ROTATION.getName(), -180, 0).start();
}
};
...
dropDownView.setDropDownListener(dropDownListener);
已下载
0