云抢购网官方网站,2017网站建设报价方案,wordpress怎么加联系工具,青岛高端网站建设公司背景#xff1a;
1、当遥控器遥控盒子#xff0c;app内是有一套机制#xff0c;响应遥控器的操作;
2、要实现遥控器选中的效果#xff0c;必须要设置setOnFocusChangeListener方法#xff0c;另外一个就是设置view的setOnClickListener方法#xff1b;设置完之后#…背景
1、当遥控器遥控盒子app内是有一套机制响应遥控器的操作;
2、要实现遥控器选中的效果必须要设置setOnFocusChangeListener方法另外一个就是设置view的setOnClickListener方法设置完之后就可以直接有遥控器选中的状态 需要做的就是
1、activity中普通view的处理 直接监听该view的“setOnFocusChangeListener”方法如下 imgTitle.setOnFocusChangeListener(this);实现方法处理Overridepublic void onFocusChange(View view, boolean hasFocus) {if (hasFocus) {//获焦后放大1.2倍ViewCompat.animate(view).scaleX(1.1f).scaleY(1.1f).translationZ(1.1f).start();} else {//丢失焦点后缩回正常ViewCompat.animate(view).scaleX(1.0f).scaleY(1.0f).translationZ(1.0f).start();}}
这样就可以响应遥控器的操作了并且还有失去、获取焦点view放大缩小的动画
view的背景都添加一个draw的xml如下
?xml version1.0 encodingutf-8?
selector xmlns:androidhttp://schemas.android.com/apk/res/androiditem android:state_focusedtrueshapecorners android:radius3dp /stroke android:width3dp android:colorcolor/white /solid android:colorcolor/transparent /padding android:top3dpandroid:bottom3dpandroid:left3dpandroid:right3dp//shape/itemitem android:state_focusedfalseshapecorners android:radius3dp /stroke android:width1dp android:colorcolor/transparent /solid android:colorcolor/transparent //shape/item
/selector2、activity中是recycleview时应该如下处理 先设置监听 recyclerViewTop.setOnFocusChangeListener(this);再将adapter中的item布局中只设置一个view的focusable是true其他的都设置成false这样遥控器就可以进行选择了同时遥控器中的ok键就是click事件
布局如下
?xml version1.0 encodingutf-8?
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthwrap_contentandroid:layout_height200dpImageViewandroid:idid/item_img_left_lineandroid:layout_width15dpandroid:focusablefalseandroid:layout_height1dp/ImageViewandroid:idid/item_img_top_lineandroid:layout_width1dpandroid:layout_height15dpandroid:focusablefalse/RelativeLayoutandroid:idid/item_layout_mainandroid:layout_widthwrap_contentandroid:layout_height105dpandroid:layout_toRightOfid/item_img_left_lineandroid:layout_belowid/item_img_top_lineandroid:focusablefalseandroid:backgroundcolor/greenImageViewandroid:idid/item_img_backgroundandroid:layout_widthmatch_parentandroid:layout_height105dpandroid:backgrounddrawable/btn_blue_round_line_selectorandroid:focusabletrue/TextViewandroid:idid/item_tv_nameandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_centerHorizontaltrueandroid:textstring/app_nameandroid:textSize16spandroid:textColorcolor/whiteandroid:layout_alignParentBottomtrueandroid:layout_marginBottom10dpandroid:focusablefalse//RelativeLayout/RelativeLayout 在activity中需要对遥控器做特殊监听的以下
Overridepublic boolean dispatchKeyEvent(KeyEvent event) {int keyCode event.getKeyCode();int action event.getAction();return handleKeyEvent(action, keyCode)||super.dispatchKeyEvent(event);}private boolean handleKeyEvent(int action, int keyCode) {if (action ! KeyEvent.ACTION_DOWN)return false;switch (keyCode) {case KeyEvent.KEYCODE_ENTER:case KeyEvent.KEYCODE_DPAD_CENTER://确定键enterbreak;case KeyEvent.KEYCODE_DPAD_DOWN://向下键break;case KeyEvent.KEYCODE_DPAD_UP://向上键break;case KeyEvent.KEYCODE_DPAD_LEFT://向左键break;case KeyEvent.KEYCODE_DPAD_RIGHT://向右键break;default:break;}return false;} Recycleview中的itemview也可以设置放大缩小的动态图