Adding Lottie animation and splashScreen with introScreen and Onbinding screen with third party library in android app
How to add Lottie animation in android app
To add lottie animation in android app
1) download image as a json file.
3) add lottie animation dependency.
2) create raw folder in res folder in android.
3) Add this code in xml layout.
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/splashscreens" />
How to set animation image after moving from one activity orclick view.add this code in layout.xml and set visible="gone" after click button the visiblity is set to visible<com.airbnb.lottie.LottieAnimationView
android:id="@+id/imagesanimation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
android:visibility="gone"
app:lottie_rawRes="@raw/splashscreens" />
android:id="@+id/imagesanimation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:lottie_autoPlay="true"
app:lottie_loop="true"
android:visibility="gone"
app:lottie_rawRes="@raw/splashscreens" />
In Backend
text.setOnClickListener(v->{ //set animation visibleanimationView.setVisibility(View.VISIBLE);Intent intent = new Intent(this,SplashScreen.class);startActivity(intent);});
Demo app
How to set image using Glide
image = findViewById(R.id.imageView);
Glide.with(this).load(R.drawable.splashimg).into(image);
How to create SplashScreen with IntroActivity
1) right click in package and create java class and setname as introActivity
SharedPreferences preferences = this.getSharedPreferences("splash",MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
Thread thread = new Thread(){
@Override
public void run() {
try{
sleep(4000);
if (preferences.getBoolean("isMain", false)) {
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
finish();
}else{
editor.putBoolean("isMain",true);
editor.apply();
TaskStackBuilder.create(SplashScreen.this).addNextIntentWithParentStack(
new Intent(SplashScreen.this,MainActivity.class))
.addNextIntent(new Intent(SplashScreen.this,IntroActivity.class))
.startActivities();
}
}catch(Exception e){
}
}
};thread.start();
1) add dependency in build gradle
implementation 'io.github.dreierf:material-intro-screen:0.0.6
2)Inside Intro activity
public class IntroActivity extends MaterialIntroActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addSlide(new SlideFragmentBuilder()
.backgroundColor(R.color.colorPrimary)
.buttonsColor(R.color.colorAccent)
.image(R.drawable.splashimg)
.title("Welcome to our app")
.description("Hello Guyz I am krish kharal from Bayatari i am a computer Engineer")
.build());
addSlide(new SlideFragmentBuilder()
.backgroundColor(R.color.colorPrimary)
.buttonsColor(R.color.colorAccent)
.image(R.drawable.splashimg)
.title("title 3")
.description("Description 3")
.build());
addSlide(new SlideFragmentBuilder()
.backgroundColor(R.color.colorPrimary)
.buttonsColor(R.color.colorAccent)
.image(R.drawable.splashimg)
.title("title 3")
.description("Description 3")
.build());
}
}
onBoarding screen and Splashscreen app demo
Set Animation in Adapters
@Override
public void onBindViewHolder(@NonNull SharyViewHolder holder, int position) {
final SharyModels models = list.get(position);
holder.title.setText(models.getTitle());
setAnimation(holder.itemView);
}
public void setAnimation(View v){
Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_out_right);
v.setAnimation(animation);
}
Comments
Post a Comment