在AndroidTV的APP里,操控逻辑都是遥控实现,所以需要在交互层面添加当前焦点所在的控件UI变化来提示用户当前操作的是哪一个按钮
最简单的莫过于大小呼吸状态的变化了,代码如下:
public static void viewChange(View v, Boolean hasFocus) {
if (hasFocus) {
ViewCompat.animate(v)
.setDuration(100)
.scaleX(1.1f)
.scaleY(1.1f)
.start();
} else {
ViewCompat.animate(v)
.setDuration(200)
.scaleX(1f)
.scaleY(1f)
.start();
}
一般我会添加到我的自定义Untils类里,控件需要调用的时候结合OnFocusChangeListener来做:
button.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Utils.viewChange(v, hasFocus);
}
});
还有一个控件呼吸闪烁的简单实现:
public static void setFlickerAnimation(View iv_chat_head, int speed) {
final Animation animation = new AlphaAnimation(1, 0);
animation.setDuration(speed);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.REVERSE);
iv_chat_head.setAnimation(animation);
}
直接Untils.setFlickerAnimation(img_view, 400)就好