-1

My task is to show some on-screen help for users when certain fragment is displayed to them. Specifically, I want to add a pulsating hover (a drawable) over an ImageView to show that it's clickable.

So what is the most optimal way to do that? And in particular, how to check if it's the first time the user has visited the fragment?

  • Can you share what code you have so far, and point to a specific part where you have an issue? This question is currently too generic - see https://stackoverflow.com/help/how-to-ask – Kevin Hooke Jan 31 '19 at 01:05

1 Answers1

0

For the pulsing hint you can try to create a hint icon, put a drawable (that you want to animate) below the hint and then just animate it. So something like this would work:

Create a layout with two ImageViews

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/pulse"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/grad_pulse"
        android:layout_centerInParent="true"/>

    <ImageView
        android:id="@+id/hint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_info"
        android:layout_centerInParent="true"/>

</RelativeLayout>

Create desired animation (pulse for example):

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="2"
    android:repeatMode="reverse"
    android:toXScale="0.5"
    android:toYScale="0.5" />

And then connect all of it in MainActivity.kt

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        animate()
    }

    private fun animate() {
        val pulse = findViewById<ImageView>(R.id.pulse)
        val anim = AnimationUtils.loadAnimation(this, R.anim.pulse)
        anim.repeatCount = Animation.INFINITE
        pulse.startAnimation(anim)
    }

}

If you want just the image itself to pulse, you can just use one ImageView and scale the icon itself.

how to check if it's the first time the user has visited the fragment?

You can use SharedPreferences. Create a key/value pair that will be set to false by default. If it is false you know it is the first time user opened your app. If that's the case just change the value to true - next time user will enter your fragment the value will be set to true, which means he has been there before.

You can use this answer as an inspiration

kristyna
  • 1,360
  • 2
  • 24
  • 41