-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
646 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ proguard/ | |
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
*.iml |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CHANGE LOG | ||
========================== | ||
|
||
1.0.0 | ||
----- | ||
Initial version of the ExpandableTextView |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,144 @@ | ||
# Android-ExpandableTextView | ||
An expandable TextView for Android applications | ||
Android-ExpandableTextView | ||
========================== | ||
An expandable TextView for Android applications (4.0+). | ||
|
||
[ ![Download](https://api.bintray.com/packages/blogcat/maven/android-expandabletextview/images/download.svg) ](https://bintray.com/blogcat/maven/android-expandabletextview/_latestVersion) | ||
|
||
Demo | ||
---- | ||
This repository also contains a demo project. | ||
|
||
![Demo](https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/release/1.0.0/demo.gif) | ||
|
||
Add dependency | ||
-------------- | ||
This library is not yet released in Maven Central, but instead you can use [Bintray](https://www.bintray.com). | ||
|
||
```groovy | ||
repositories { | ||
maven { | ||
url "https://dl.bintray.com/blogcat/maven" | ||
} | ||
} | ||
``` | ||
|
||
library dependency | ||
|
||
```groovy | ||
dependencies { | ||
compile ('at.blogc:expandabletextview:1.0.0@aar') | ||
} | ||
``` | ||
|
||
Usage | ||
----- | ||
Using the ExpandableTextView is very easy, it's just a regular TextView with some extra functionality added to it. By defining the android:maxLines attribute, you can set the default number of lines for the TextView collapsed state. | ||
|
||
```xml | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<at.blogc.android.views.ExpandableTextView | ||
android:id="@+id/expandableTextView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/lorem_ipsum" | ||
android:maxLines="5" | ||
android:ellipsize="end" | ||
app:animation_duration="1000"/> | ||
|
||
<!-- Optional parameter animation_duration: sets the duration of the expand animation --> | ||
|
||
<Button | ||
android:id="@+id/button_toggle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/expand"/> | ||
|
||
</LinearLayout> | ||
``` | ||
|
||
In your Activity or Fragment: | ||
|
||
```java | ||
final ExpandableTextView expandableTextView = (ExpandableTextView) this.findViewById(R.id.expandableTextView); | ||
final Button buttonToggle = (Button) this.findViewById(R.id.button_toggle); | ||
|
||
// set animation duration via code, but preferable in your layout files by using the animation_duration attribute | ||
expandableTextView.setAnimationDuration(1000L); | ||
|
||
// toggle the ExpandableTextView | ||
buttonToggle.setOnClickListener(new View.OnClickListener() | ||
{ | ||
@Override | ||
public void onClick(final View v) | ||
{ | ||
expandableTextView.toggle(); | ||
buttonToggle.setText(expandableTextView.isExpanded() ? R.string.collapse : R.string.expand); | ||
} | ||
}); | ||
|
||
// but, you can also do the checks yourself | ||
buttonToggle.setOnClickListener(new View.OnClickListener() | ||
{ | ||
@Override | ||
public void onClick(final View v) | ||
{ | ||
if (expandableTextView.isExpanded()) | ||
{ | ||
expandableTextView.collapse(); | ||
buttonToggle.setText(R.string.expand); | ||
} | ||
else | ||
{ | ||
expandableTextView.expand(); | ||
buttonToggle.setText(R.string.collapse); | ||
} | ||
} | ||
}); | ||
|
||
// listen for expand / collapse events | ||
expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener() | ||
{ | ||
@Override | ||
public void onExpand(final ExpandableTextView view) | ||
{ | ||
Log.d(TAG, "ExpandableTextView expanded"); | ||
} | ||
|
||
@Override | ||
public void onCollapse(final ExpandableTextView view) | ||
{ | ||
Log.d(TAG, "ExpandableTextView collapsed"); | ||
} | ||
}); | ||
``` | ||
|
||
Roadmap | ||
======= | ||
|
||
* take into account TextView padding and margin | ||
* optional fading edge at the bottom of the TextView | ||
* support for Interpolators | ||
* update demo project with more examples | ||
|
||
License | ||
======= | ||
|
||
Copyright 2016 Cliff Ophalvens (Blogc.at) | ||
|
||
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. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ogc/at/android/views/ApplicationTest.java → .../blogc/android/views/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.