Support
Quality
Security
License
Reuse
kandi has reviewed lottie-android and discovered the below as its top functions. This is intended to give you an instant insight into lottie-android implemented functionality, and help decide if they suit your requirements.
Render After Effects animations natively on Android and iOS, Web, and React Native
Download
dependencies {
implementation 'com.airbnb.android:lottie:$lottieVersion'
}
How to know when lottie animation is completed?
mAddedToCartAnimation.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.e("Animation:","start");
}
@Override
public void onAnimationEnd(Animator animation) {
Log.e("Animation:","end");
//Your code for remove the fragment
try {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(this).commit();
} catch(Exception ex) {
ex.toString();
}
}
@Override
public void onAnimationCancel(Animator animation) {
Log.e("Animation:","cancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.e("Animation:","repeat");
}
});
-----------------------
<RelativeLayout
android:id="@+id/contanierForAnimationId"
android:layout_width="50dp"
android:layout_height="50dp"
android:visibility="visible">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/aLottieAnimationId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_autoPlay="false"
app:lottie_fileName="animation.json"
app:lottie_repeatCount="0" />
</RelativeLayout>
var aLottieAnimationId : LottieAnimationView? = null
var contanierForAnimationId: RelativeLayout? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate( R.layout.my_Layout, container, false )
aLottieAnimationId = view.findViewById(R.id.aLottieAnimationId) as LottieAnimationView
contanierForAnimationId = view.findViewById(R.id.contanierForAnimationId) as RelativeLayout
aLottieAnimationId?.setOnClickListener {
aLottieAnimationId?.setOnClickListener(null)
aLottieAnimationId?.speed = 1f
aLottieAnimationId?.playAnimation()
aLottieAnimationId?.setMinAndMaxFrame(0, 90) //How many frames does the animation have
aLottieAnimationId?.addAnimatorUpdateListener { valueAnimator ->
// Set animation progress
val progress = (valueAnimator.animatedValue as Float * 100).toInt()
Log.d("progress :","$progress")
//You must know How many frames does the animation have
if (progress == 90) {
contanierForAnimationId?.visibility = View.GONE
}
}
}
return view
}
-----------------------
<RelativeLayout
android:id="@+id/contanierForAnimationId"
android:layout_width="50dp"
android:layout_height="50dp"
android:visibility="visible">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/aLottieAnimationId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_autoPlay="false"
app:lottie_fileName="animation.json"
app:lottie_repeatCount="0" />
</RelativeLayout>
var aLottieAnimationId : LottieAnimationView? = null
var contanierForAnimationId: RelativeLayout? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate( R.layout.my_Layout, container, false )
aLottieAnimationId = view.findViewById(R.id.aLottieAnimationId) as LottieAnimationView
contanierForAnimationId = view.findViewById(R.id.contanierForAnimationId) as RelativeLayout
aLottieAnimationId?.setOnClickListener {
aLottieAnimationId?.setOnClickListener(null)
aLottieAnimationId?.speed = 1f
aLottieAnimationId?.playAnimation()
aLottieAnimationId?.setMinAndMaxFrame(0, 90) //How many frames does the animation have
aLottieAnimationId?.addAnimatorUpdateListener { valueAnimator ->
// Set animation progress
val progress = (valueAnimator.animatedValue as Float * 100).toInt()
Log.d("progress :","$progress")
//You must know How many frames does the animation have
if (progress == 90) {
contanierForAnimationId?.visibility = View.GONE
}
}
}
return view
}
-----------------------
successAnimation.addAnimatorListener(object : Animator.AnimatorListener{
override fun onAnimationRepeat(animation: Animator?) {
}
override fun onAnimationEnd(animation: Animator?) {
//Add your code here for animation end
}
override fun onAnimationCancel(animation: Animator?) {
}
override fun onAnimationStart(animation: Animator?) {
}
})
Lottie Android: add color overlay to animation
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
new KeyPath("**"),
LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
}
}
);
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
new KeyPath("checkmark", "**"),
LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return new PorterDuffColorFilter(Color.CYAN, PorterDuff.Mode.SRC_ATOP);
}
}
);
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(new KeyPath("**"), LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return null;
}
}
);
-----------------------
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
new KeyPath("**"),
LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
}
}
);
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
new KeyPath("checkmark", "**"),
LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return new PorterDuffColorFilter(Color.CYAN, PorterDuff.Mode.SRC_ATOP);
}
}
);
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(new KeyPath("**"), LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return null;
}
}
);
-----------------------
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
new KeyPath("**"),
LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.SRC_ATOP);
}
}
);
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(
new KeyPath("checkmark", "**"),
LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return new PorterDuffColorFilter(Color.CYAN, PorterDuff.Mode.SRC_ATOP);
}
}
);
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addValueCallback(new KeyPath("**"), LottieProperty.COLOR_FILTER,
new SimpleLottieValueCallback<ColorFilter>() {
@Override
public ColorFilter getValue(LottieFrameInfo<ColorFilter> frameInfo) {
return null;
}
}
);
-----------------------
int yourColor = ContextCompat.getColor(getContext(),R.color.colorPrimary);
SimpleColorFilter filter = new SimpleColorFilter(yourColor);
KeyPath keyPath = new KeyPath("**");
LottieValueCallback<ColorFilter> callback = new LottieValueCallback<ColorFilter>(filter);
animationView.addValueCallback(keyPath, LottieProperty.COLOR_FILTER, callback);
-----------------------
int yourColor = ContextCompat.getColor(getContext(),R.color.colorPrimary);
SimpleColorFilter filter = new SimpleColorFilter(yourColor);
KeyPath keyPath = new KeyPath("**");
LottieValueCallback<ColorFilter> callback = new LottieValueCallback<ColorFilter>(filter);
animationView.addValueCallback(keyPath, LottieProperty.COLOR_FILTER, callback);
-----------------------
"sc": "#6664e7"
Is it possible to add custom drawable to imageView in an Android Home Screen Widget?
Paint p = new Paint();
p.setAntiAlias(true);
p.setStyle(Style.STROKE);
p.setStrokeWidth(8);
p.setColor(0xFFFF0000);
Bitmap bitmap = Bitmap.createBitmap(100, 100,
Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawArc(new RectF(10, 10, 90, 90), 0, 270, false, p);
RemoteViews views = new
RemoteViews(updateService.getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.canvas, bitmap);
ComponentName componentName = new
ComponentName(updateService,
DashboardAppWidgetProvider.class);
AppWidgetManager appWidgetManager =
AppWidgetManager.getInstance(updateService);
appWidgetManager.updateAppWidget(componentName,
views);
How to interpret and translate kotlin code to java?
private void setViewPagerScroller() {
try {
Field scrollerField = ViewPager.class.getDeclaredField("mScroller");
scrollerField.setAccessible(true);
Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
interpolator.setAccessible(true);
Scroller scroller = new Scroller(this, (android.view.animation.Interpolator) interpolator.get(null)){
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
super.startScroll(startX, startY, dx, dy, duration * 7);
}
}
scrollerField.set(viewPager, scroller);
} catch (NoSuchFieldException error) {
// Do nothing.
} catch (IllegalAccessException error) {
// Do nothing.
}
}
private LockableViewPager viewPager;
private LockableViewPager getViewPager(){
if(viewPager == null){
// produce viewpager and store in field
}
return viewPager;
}
-----------------------
private void setViewPagerScroller() {
try {
Field scrollerField = ViewPager.class.getDeclaredField("mScroller");
scrollerField.setAccessible(true);
Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
interpolator.setAccessible(true);
Scroller scroller = new Scroller(this, (android.view.animation.Interpolator) interpolator.get(null)){
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
super.startScroll(startX, startY, dx, dy, duration * 7);
}
}
scrollerField.set(viewPager, scroller);
} catch (NoSuchFieldException error) {
// Do nothing.
} catch (IllegalAccessException error) {
// Do nothing.
}
}
private LockableViewPager viewPager;
private LockableViewPager getViewPager(){
if(viewPager == null){
// produce viewpager and store in field
}
return viewPager;
}
Gradle dependency conflict between library and project android
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
def supportLibrariesVersion = '26.1.0'
compile "com.android.support:support-compat:${supportLibrariesVersion}"
compile "com.android.support:cardview-v7:${supportLibrariesVersion}"
compile "com.android.support:recyclerview-v7:${supportLibrariesVersion}"
compile "com.android.support:gridlayout-v7:${supportLibrariesVersion}"
compile "com.android.support:design:${supportLibrariesVersion}"
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
-----------------------
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
def supportLibrariesVersion = '26.1.0'
compile "com.android.support:support-compat:${supportLibrariesVersion}"
compile "com.android.support:cardview-v7:${supportLibrariesVersion}"
compile "com.android.support:recyclerview-v7:${supportLibrariesVersion}"
compile "com.android.support:gridlayout-v7:${supportLibrariesVersion}"
compile "com.android.support:design:${supportLibrariesVersion}"
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
-----------------------
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
def supportLibrariesVersion = '26.1.0'
compile "com.android.support:support-compat:${supportLibrariesVersion}"
compile "com.android.support:cardview-v7:${supportLibrariesVersion}"
compile "com.android.support:recyclerview-v7:${supportLibrariesVersion}"
compile "com.android.support:gridlayout-v7:${supportLibrariesVersion}"
compile "com.android.support:design:${supportLibrariesVersion}"
}
compileSdkVersion 26
buildToolsVersion "26.0.1"
-----------------------
repositories {
google()
}
repositories {
maven {
url "https://maven.google.com"
}
}
-----------------------
repositories {
google()
}
repositories {
maven {
url "https://maven.google.com"
}
}
Lottie animation slow android
final LottieAnimationView animationView = (LottieAnimationView) findViewById(R.id.animation_view);
animationView.useExperimentalHardwareAcceleration(true);
animationView.enableMergePathsForKitKatAndAbove(true);
QUESTION
How to know when lottie animation is completed?
Asked 2020-May-20 at 16:13I have a fragment, here is the onCreateView method:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
mView = inflater.inflate(R.layout.fragment_added_to_cart_anim, container, false);
ButterKnife.bind(this, mView);
mAddedToCartAnimation.setAnimation("checked_done_.json");
mAddedToCartAnimation.loop(false);
mAddedToCartAnimation.playAnimation();
// Remove fragment when the animation is finished.
return mView;
}
I need to remove the fragment using getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
when the lottie animation has ended. If I understand correctly when the isAnimating()
Lottie method returns false the animation has ended and since in my configuration the animation does not loop this is when I should remove the current fragment. But I can't just use an if statement since when it is executed the animation may still be going.
I need a way to remove the fragment when the Lottie animation ends, how do I do this?
ANSWER
Answered 2017-Sep-12 at 16:17This code works for me:
mAddedToCartAnimation.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.e("Animation:","start");
}
@Override
public void onAnimationEnd(Animator animation) {
Log.e("Animation:","end");
//Your code for remove the fragment
try {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(this).commit();
} catch(Exception ex) {
ex.toString();
}
}
@Override
public void onAnimationCancel(Animator animation) {
Log.e("Animation:","cancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.e("Animation:","repeat");
}
});
I hope this solve your problem :)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit