I need to add a GIF in my code snippet on the screen, i need it to be played continuously
and without stopping I saw many blogs, QnAs on google but I didn't find the answer, here goes my MainActivity.java(Showing MainActivity.class as it was not allowing me to post the whole code) -
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView lightUp = findViewById(R.id.lightUp4);
Button unLight = findViewById(R.id.unlight);
ImageView AgarbattiBtn = findViewById(R.id.agarbattiBtn);
MediaPlayer Sound_matchstick = MediaPlayer.create(this, R.raw.matchstick);
MediaPlayer Om_Bhur = MediaPlayer.create(this, R.raw.om_bhur);
lightUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageView image1 = findViewById(R.id.diya);
image1.setImageResource(R.drawable.lit_diya);
lightUp.setVisibility(View.INVISIBLE);
Sound_matchstick.start();
if(lightUp.getVisibility() == View.INVISIBLE && AgarbattiBtn.getVisibility() == View.INVISIBLE){
Om_Bhur.start();
}
}
});
unLight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageView image2 = findViewById(R.id.diya);
image2.setImageResource(R.drawable.not_lit_diya);
AgarbattiBtn.setVisibility(View.VISIBLE);
findViewById(R.id.agrabatti).setVisibility(View.INVISIBLE);
lightUp.setVisibility(View.VISIBLE);
Om_Bhur.stop();
}
});
AgarbattiBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AgarbattiBtn.setVisibility(View.INVISIBLE);
findViewById(R.id.agrabatti).setVisibility(View.VISIBLE);
if(lightUp.getVisibility() == View.INVISIBLE && AgarbattiBtn.getVisibility() == View.INVISIBLE){
Om_Bhur.start();
}
}
});
}
}
This is my activity_main.xml -
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/mandir"
android:layout_width="508dp"
android:layout_height="521dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.39"
app:srcCompat="@mipmap/mandir" />
<Button
android:id="@+id/unlight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.96" />
<ImageView
android:id="@+id/diya"
android:layout_width="78dp"
android:layout_height="62dp"
app:layout_constraintBottom_toBottomOf="@+id/mandir"
app:layout_constraintEnd_toEndOf="@+id/mandir"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toStartOf="@+id/mandir"
app:layout_constraintTop_toTopOf="@+id/mandir"
app:layout_constraintVertical_bias="0.75"
app:srcCompat="@mipmap/not_lit_diya" />
<ImageView
android:id="@+id/lightUp4"
android:layout_width="142dp"
android:layout_height="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/unlight"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="@drawable/matchstick" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="68dp"
android:layout_height="81dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.55"
app:srcCompat="@drawable/krishna_ji" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="78dp"
android:layout_height="84dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.76"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.55"
app:srcCompat="@drawable/mata_rani" />
<ImageView
android:id="@+id/agarbattiBtn"
android:layout_width="80dp"
android:layout_height="105dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.86"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="@drawable/agarbatti" />
<ImageView
android:id="@+id/agrabatti"
android:layout_width="86dp"
android:layout_height="104dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.56"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.59000003"
app:srcCompat="@drawable/agarbatti" />
</androidx.constraintlayout.widget.ConstraintLayout>
Thanks in advance...
question from:
https://stackoverflow.com/questions/66065263/add-a-gif-in-android-studio-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…