Возможно, вы сможете сделать это с помощью xpath. что-то вроде //tr[contains(@class, 'row') and position() mod 2 = 0]
может работать. Существуют другие вопросы SO, расширяющие подробности о том, как более точно сопоставлять классы.
R.anim.pulse
:
<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="1"
android:repeatMode="reverse"
android:toXScale="0.5"
android:toYScale="0.5" />
ImageView imageView = (ImageView) findViewById(R.id.image);
Animation pulse = AnimationUtils.loadAnimation(this, R.anim.pulse);
imageView.startAnimation(pulse);
heart_pulse.xml поместите heart_pulse.xml в папку res / anim. Добавьте android: interpolator
, затем используйте в своей деятельности, как показано ниже
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="reverse"/>
ImageView imageView =(ImageView)findViewById(R.id.imageView);
Animation pulse = AnimationUtils.loadAnimation(this, R.anim.heart_pulse);
imageView.startAnimation(pulse);
Чтобы использовать решение @ Matthias Robbers напрямую из XML, вы можете сделать следующее: создать 2 файла:
1- pulse.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.8"
android:toYScale="0.8"
android:duration="500"
android:repeatCount="infinite"
android:repeatMode="reverse"/>
</set>
2- pulse_layout_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/pulse">
</layoutAnimation>
, затем в своем XML-файле макета просто добавьте эту анимацию в любой необходимый вам просмотр, например:
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:src="@drawable/heart"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layoutAnimation="@anim/pulse_layout_animation" />