簡體   English   中英

立即使lottie animation 設置可見性

[英]make lottie animation setVisibility immediately

我有一個 adroid 項目,我想在算法運行期間顯示一個樂天 animation,但它有時不可見。

在我的 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" />

// 我也試過 android:visibility="invisible"

在 java 中:

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

在我想開始查看 animation 的特定 function 中,我寫道:

lottieanimationview.setVisibility(LottieAnimationView.VISIBLE);

然后,在這個 function 中,我調用了另一個運行算法的 function(在項目中的 cpp 文件中)。

現在,不是變得可見然后運行另一個 function(我希望它像加載動畫),而是在第二個 function 運行完成后才可見。 當我調用 setVisibility 時,如何讓 lottie 立即可見? 謝謝你

好的..這是我嘗試過的代碼:

我對此有一些樂透觀點(下面附有截圖)。 但是我們將只使用切換視圖和 thumbsDown 當我們打開切換時,我們將拇指向下視圖的可見性設置為消失,當我們關閉切換時,拇指向下視圖再次可見。

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

公共 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); } } }

在此處輸入圖像描述

主要的是:

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

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM