Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyFermin authored Jul 12, 2017
1 parent b491bc5 commit 3e4af12
Showing 1 changed file with 61 additions and 38 deletions.
99 changes: 61 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,94 @@
### Ensure your minSdkVersion is 19 or above:

```
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.anthonyfdev.dropdownviewexample"
minSdkVersion 19
targetSdkVersion 25
}
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.anthonyfdev.dropdownviewexample"
minSdkVersion 19
targetSdkVersion 25
}
}
```

#### Add jitpack repository to your root build.gradle:
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

#### Add dependency to app level build.gradle:
```
dependencies {
compile 'com.github.AnthonyFermin:DropDownView:1.0.1'
}
dependencies {
compile 'com.github.AnthonyFermin:DropDownView:1.0.1'
}
```

### Usage

#### Add view to 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"/>
<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"/>
```

#### 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 = (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);
```

#### Set header and expanded views to DropDownView:
```
dropDownView.setHeaderView(collapsedView);
dropDownView.setExpandedView(expandedView);
dropDownView.setHeaderView(collapsedView);
dropDownView.setExpandedView(expandedView);
```

#### Call expand or collapse:
```
collapsedView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dropDownView.isExpanded()) {
dropDownView.collapseDropDown();
} else {
dropDownView.expandDropDown();
}
}
});
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);
```

#### Done!
Expand Down

0 comments on commit 3e4af12

Please sign in to comment.