欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android TV listview及焦點(diǎn)處理

 更新時(shí)間:2017年06月13日 15:30:50   作者:chenrunhua  
這篇文章主要介紹了Android TV listview及焦點(diǎn)處理的相關(guān)資料,需要的朋友可以參考下

Android TV listview及焦點(diǎn)處理

Android TV上的listview ,因?yàn)闆]有touch事件,只能通過按鍵處理,因此,用到listview時(shí)需要特殊處理:

1.復(fù)雜的view需要獲取焦點(diǎn),需要設(shè)置:

setItemsCanFocus(true)

同時(shí)需要設(shè)置下能獲取焦點(diǎn)view的屬性:

android:focusable="true

這樣子級(jí)view就可以獲取獲取焦點(diǎn)。

2.view中需要獲取焦點(diǎn)需要高亮框效果,可以在view畫外框:

package com.cn21.ecloud.tv.ui.widget; 
 
import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Rect; 
import android.graphics.drawable.Drawable; 
import android.util.AttributeSet; 
import android.widget.RelativeLayout; 
 
public class SelectedRelativeLayout extends RelativeLayout{ 
  private Drawable mFloatDrawable; 
  private Rect mTempRect = new Rect(); 
 
  public SelectedRelativeLayout(Context context) { 
    this(context, null, 0); 
  } 
 
  public SelectedRelativeLayout(Context context, AttributeSet attrs) { 
    this(context, attrs, 0); 
  } 
 
  public SelectedRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
    mFloatDrawable = getResources().getDrawable(R.drawable.item_float_rectangle); 
  } 
 
  @Override 
  protected void dispatchDraw(Canvas canvas) { 
    super.dispatchDraw(canvas); 
    if (hasFocus()) { 
      if (mFloatDrawable != null) { 
        final int w = getMeasuredWidth(); 
        final int h = getMeasuredHeight(); 
        mFloatDrawable.getPadding(mTempRect); 
        mFloatDrawable.setBounds(-mTempRect.left, -mTempRect.top, 
            w + mTempRect.right, h + mTempRect.bottom); 
        mFloatDrawable.draw(canvas); 
      } 
    } 
  } 
} 

布局中直接使用這個(gè)view

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論