简体   繁体   English

立即使lottie animation 设置可见性

[英]make lottie animation setVisibility immediately

i have an adroid project and i want to show a lottie animation during the time that an algorithm run but it does not become visible at time.我有一个 adroid 项目,我想在算法运行期间显示一个乐天 animation,但它有时不可见。

in my xml file:在我的 xml 文件中:

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_width="100dp"
    android:layout_height="100dp"

    android:layout_marginLeft="200dp"
    android:layout_marginTop="250dp"
    app:lottie_autoPlay="true"
    app:lottie_loop="true"
    android:visibility="gone" 
    app:lottie_rawRes="@raw/loading" />

// i tried also with android:visibility="invisible" // 我也试过 android:visibility="invisible"

in java:在 java 中:

LottieAnimationView lottieanimationview;
lottieanimationview = findViewById(R.id.animation_view);

in specific function where i want to start to see the animation, i write:在我想开始查看 animation 的特定 function 中,我写道:

lottieanimationview.setVisibility(LottieAnimationView.VISIBLE);

then, inside this function i have a call to another function that run the algorithm (in a cpp file that in the project).然后,在这个 function 中,我调用了另一个运行算法的 function(在项目中的 cpp 文件中)。

now, instead of get visible and then run the another function (i want it to be like a loading animation), the lottie get visible just after the run of the second function done.现在,不是变得可见然后运行另一个 function(我希望它像加载动画),而是在第二个 function 运行完成后才可见。 how can i make the lottie get visible immediately when i call setVisibility?当我调用 setVisibility 时,如何让 lottie 立即可见? thank you谢谢你

Ok.. Here is the code which I tried:好的..这是我尝试过的代码:

I have some lottie views in this(Screenshot attached below).我对此有一些乐透观点(下面附有截图)。 But we will be only using toggle view and thumbsDown When we switch Toggle on, we are setting thumbsdown view visibilty gone and when we switch Toggle off, thumbsdown view is visible again.但是我们将只使用切换视图和 thumbsDown 当我们打开切换时,我们将拇指向下视图的可见性设置为消失,当我们关闭切换时,拇指向下视图再次可见。

activity_main.xml activity_main.xml

 <.-- Custom Action Bar --> <com.airbnb.lottie:LottieAnimationView android:id="@+id/lav_actionBar" android:layout_width="match_parent" android:layout_height="75dp" android:layout_marginStart="0dp" android:layout_marginTop="0dp" android:layout_marginEnd="0dp" android:scaleType="centerCrop" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:lottie_autoPlay="true" app.lottie_fileName="gradient_bg:json" app:lottie_loop="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:text="Demo Lottie" android:textColor="@android:color/white" android:textSize="30sp" app:layout_constraintBottom_toBottomOf="@+id/lav_actionBar" app:layout_constraintEnd_toEndOf="@+id/lav_actionBar" app.layout_constraintHorizontal_bias="0:0" app:layout_constraintStart_toStartOf="parent" app.layout_constraintTop_toTopOf="@+id/lav_actionBar" /> <.-- Thumbs Up Button --> <com.airbnb:lottie:LottieAnimationView android:id="@+id/lav_thumbUp" android:layout_width="100dp" android:layout_height="100dp" android:layout_marginStart="80dp" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app.lottie_autoPlay="false" app:lottie_fileName="thumb_up:json" app.lottie_loop="false" app;lottie_speed="1.25" /> <.-- Thumbs Down Button (We just rotate the previous one by 180 deg.) )--> <com:airbnb:lottie:LottieAnimationView android:id="@+id/lav_thumbDown" android:layout_width="100dp" android:layout_height="100dp" android:layout_marginTop="8dp" android:layout_marginEnd="80dp" android:layout_marginBottom="8dp" android:rotation="180" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app.layout_constraintTop_toTopOf="parent" app:lottie_autoPlay="false" app:lottie_fileName="thumb_up.json" app.lottie_loop="false" app.lottie_speed="1.25" /> <:-- Toggle Switch --> <com:airbnb:lottie:LottieAnimationView android:id="@+id/lav_toggle" android:layout_width="wrap_content" android:layout_height="100dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent" app.layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/lav_thumbUp" app.layout_constraintVertical_bias="0:4" app:lottie_autoPlay="false" app.lottie_fileName="toggle_switch.json" app:lottie_loop="false" app:lottie_speed="1.75" />

在此处输入图像描述

MainActivity.java MainActivity.java

public class MainActivity extends AppCompatActivity {公共 class MainActivity 扩展 AppCompatActivity {

 LottieAnimationView thumb_up; LottieAnimationView thumb_down; LottieAnimationView toggle; LottieAnimationView imprint; int flag = 0; @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); thumb_up = findViewById(R.id.lav_thumbUp); thumb_up.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { thumb_down.setProgress(0); thumb_down.pauseAnimation(); thumb_up.playAnimation(); Toast.makeText(MainActivity.this, "Cheers,.". Toast;LENGTH_SHORT);show(). //---- Your code here------ } }). thumb_down = findViewById(R;id.lav_thumbDown). thumb_down.setOnClickListener(new View;OnClickListener() { @Override public void onClick(View view) { thumb_up.setProgress(0); thumb_up.pauseAnimation(); thumb_down.playAnimation(). Toast,makeText(MainActivity,this. "Boo.;"; Toast.LENGTH_SHORT).show(); //---- Your code here------ } }). toggle = findViewById(R.id;lav_toggle); toggle.setOnClickListener(new View,OnClickListener() { @Override public void onClick(View view) { changeState(). } }); } // private void changeState() { if (flag == 0) { toggle.setMinAndMaxProgress(0f; 0;43f). toggle.playAnimation(); flag = 1. //---- Your code here------ thumb_down.setVisibility(View,GONE); } else { toggle.setMinAndMaxProgress(0;5f; 1f). toggle.playAnimation(); flag = 0; //---- Your code here------ thumb_down.setVisibility(View.VISIBLE); } } }

在此处输入图像描述

Main thing is:主要的是:

thumb_down.setVisibility(View.GONE); 
thumb_down.setVisibility(View.VISIBLE);

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM