I am trying to expand a TextView with animation and as per several SO posts and tutorials I have gotten what I think should work. The following code does set the ellipsize property based on whether the TextView is expanded or not and changes the button image as well.
It does not actually expand the text view though, is it something in my layout that is not letting it push the content below the text view down?
Layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="445dp"
android:padding="5dp"
android:layout_marginTop="20dp">
<LinearLayout
android:id="@+id/outerMainCardLayout"
android:layout_width="match_parent"
android:layout_height="430dp"
android:layout_gravity="center_horizontal|top"
android:orientation="vertical"
android:background="@drawable/swipecard_shadow"
android:gravity="top"
android:layout_marginLeft="5dp">
<LinearLayout
android:id="@+id/mainCardLayout"
android:layout_width="match_parent"
android:layout_height="430dp"
android:layout_gravity="center_horizontal|top"
android:orientation="vertical"
android:weightSum="1"
android:background="#FFFFFF"
android:gravity="top">
<TextView
android:id="@+id/tv_jobTitle"
android:background="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#505353"
android:textAlignment="center"
tools:text="General Labourer"
android:layout_gravity="center_horizontal|left"/>
<TextView
android:id="@+id/tv_companyName"
android:background="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#505353"
android:textAlignment="center"
tools:text="ABC Company"
android:layout_gravity="center_horizontal|left"
android:paddingLeft="10dp" />
<View
android:id="@+id/titleDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:minHeight="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@color/laborswipe_lightgray"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:visibility="invisible" />
<LinearLayout
android:id="@+id/cardHeaderLabels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="@+id/tv_experienceReqHeader"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginLeft="10dp"
android:textSize="12sp"
android:textColor="#f29d00"
android:drawableTop="@drawable/ic_briefcase"
android:text="Experience"
android:layout_gravity="center"
android:gravity="center"/>
<View
android:layout_width="10dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_locationLabel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="12sp"
android:textColor="#f29d00"
android:drawableTop="@drawable/ic_location"
android:text="Location"
android:layout_gravity="center"
android:gravity="center"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_payRateLabel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginRight="10dp"
android:textSize="12sp"
android:textColor="#f29d00"
android:drawableTop="@drawable/ic_payrate"
android:text="Payment (hr)"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:id="@+id/cardHeaderData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="@+id/tv_experienceReq"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginLeft="10dp"
android:textSize="14sp"
android:textColor="#505353"
tools:text="3-5 years"
android:layout_gravity="center"
android:gravity="center" />
<View
android:layout_width="10dp"
android:layout_height="0dp"
android:layout_weight="0" />
<TextView
android:id="@+id/tv_location"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="14sp"
android:textColor="#505353"
tools:text="Vancouver"
android:textAlignment="center"
android:layout_gravity="center"
android:gravity="center" />
<View
android:layout_width="10dp"
android:layout_height="0dp"
android:layout_weight="0" />
<TextView
android:id="@+id/tv_payRate"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="14sp"
android:textColor="#505353"
tools:text="$25"
android:textAlignment="center"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
<View
android:id="@+id/descriptionTopDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:minHeight="1dp"
android:background="@color/laborswipe_lightgray"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" />
<TextView
android:id="@+id/tv_JobDesc"
android:textSize="14sp"
android:textColor="#505353"
android:text="aasdf
a
a
a
a
"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="#ffffff"
android:minLines="3"
android:maxLines="3"
android:ellipsize="end" />
<Button
android:id="@+id/btn_descExpand"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginEnd="10dp"
android:layout_gravity="right"
android:drawableTop="@drawable/arrow_expand"
android:background="?android:attr/selectableItemBackground"/>
<View
android:id="@+id/descriptionBottomDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:minHeight="1dp"
android:background="@color/laborswipe_lightgray"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" />
<LinearLayout
android:id="@+id/cardFooterLabels"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TextView
android:id="@+id/tv_dateRangeLabel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="12sp"
android:textColor="#f29d00"
android:layout_marginLeft="10dp"
android:drawableTop="@drawable/ic_date"
android:text="Start - End"
android:layout_gravity="center"
android:gravity="center"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_durationLabel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:textSize="12sp"
android:textColor="#f29d00"
android:drawableTop="@drawable/ic_clock"
android:text="Paid Hours"
android:layout_gravity="center"
android:gravity="center"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_requirementsLabel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="12sp"
android:textColor="#f29d00"
android:layout_marginRight="10dp"
android:drawableTop="@drawable/ic_hardhat"
android:text="Requirements"
android:layout_gravity="center"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
onClickListener:
holder.expand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isExpanded) {
expand.setCompoundDrawablesRelativeWithIntrinsicBounds(0, R.drawable.arrow_expand, 0, 0);
Toast.makeText(context, "Collapsed", Toast.LENGTH_SHORT).show();
//desc.setMaxLines(3);
ObjectAnimator animation = ObjectAnimator.ofInt(
desc,
"maxLines",
3);
animation.setDuration(200);
animation.start();
desc.setEllipsize(TextUtils.TruncateAt.END);
isExpanded = false;
} else {
expand.setCompoundDrawablesRelativeWithIntrinsicBounds(0, R.drawable.arrow_collapse, 0, 0);
Toast.makeText(context, "Expanded", Toast.LENGTH_SHORT).show();
//desc.setMaxLines(Integer.MAX_VALUE);
ObjectAnimator animation = ObjectAnimator.ofInt(
desc,
"maxLines",
25);
animation.setDuration(200);
animation.start();
desc.setEllipsize(null);
isExpanded = true;
}
}
});
Thanks for the help!
EDIT:
Logcat of clicking expans:
07-17 13:29:15.322 20881-20907/com.lorentzos.swipecards.example W/EGL_emulation: eglSurfaceAttrib not implemented
07-17 13:29:15.322 20881-20907/com.lorentzos.swipecards.example W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3119160, error=EGL_SUCCESS
07-17 13:29:17.282 20881-20907/com.lorentzos.swipecards.example E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa2b16770
Logcat of collapsing:
07-17 13:30:18.614 20881-20907/com.lorentzos.swipecards.example W/EGL_emulation: eglSurfaceAttrib not implemented
07-17 13:30:18.614 20881-20907/com.lorentzos.swipecards.example W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa32be800, error=EGL_SUCCESS
07-17 13:30:20.543 20881-20907/com.lorentzos.swipecards.example E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab7daa70