Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ protected void onCreate(final Bundle savedInstanceState)
final ExpandableTextView expandableTextView = (ExpandableTextView) this.findViewById(R.id.expandableTextView);
final Button buttonToggle = (Button) this.findViewById(R.id.button_toggle);

// set max lines via code
expandableTextView.setMaxLines(3);

// set animation duration via code, but preferable in your layout files by using the animation_duration attribute
expandableTextView.setAnimationDuration(750L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ExpandableTextView extends TextView
private TimeInterpolator expandInterpolator;
private TimeInterpolator collapseInterpolator;

private final int maxLines;
private int maxLines;
private long animationDuration;
private boolean animating;
private boolean expanded;
Expand Down Expand Up @@ -101,7 +101,14 @@ public int getMaxLines()
return -1;
}
}


@Override
public void setMaxLines(int maxLines)
{
super.setMaxLines(maxLines);
this.maxLines = maxLines;
}

/**
* Toggle the expanded state of this {@link ExpandableTextView}.
* @return true if toggled, false otherwise.
Expand Down Expand Up @@ -139,7 +146,7 @@ public boolean expand()
this.collapsedHeight = this.getMeasuredHeight();

// set maxLines to MAX Integer, so we can calculate the expanded height
this.setMaxLines(Integer.MAX_VALUE);
super.setMaxLines(Integer.MAX_VALUE);

// get expanded height
this.measure
Expand Down Expand Up @@ -232,7 +239,7 @@ public void onAnimationUpdate(final ValueAnimator animation)
public void onAnimationEnd(final Animator animation)
{
// set maxLines to original value
ExpandableTextView.this.setMaxLines(ExpandableTextView.this.maxLines);
ExpandableTextView.super.setMaxLines(ExpandableTextView.this.maxLines);

// if fully collapsed, set height to WRAP_CONTENT, because when rotating the device
// the height calculated with this ValueAnimator isn't correct anymore
Expand Down