You can accomplish this by your own approach i.e. using android:onClick
attribute:
Assign one function to both ImageButton
for example btns_clicked()
. So add android:onClick='btns_clicked'
to both your buttons. And in that function write:
public void btns_clicked(View v) {
View btn1 = findViewById(R.id.btn1);
View btn2 = findViewById(R.id.btn2);
btn1.startAnimation(animLeftTranslate);
btn2.startAnimation(animRightTranslate);
}