国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android TV listview及焦點處理

2019-12-12 02:41:08
字體:
來源:轉載
供稿:網友

Android TV listview及焦點處理

Android TV上的listview ,因為沒有touch事件,只能通過按鍵處理,因此,用到listview時需要特殊處理:

1.復雜的view需要獲取焦點,需要設置:

setItemsCanFocus(true)

同時需要設置下能獲取焦點view的屬性:

android:focusable="true

這樣子級view就可以獲取獲取焦點。

2.view中需要獲取焦點需要高亮框效果,可以在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);       }     }   } } 

布局中直接使用這個view

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 恩平市| 宝鸡市| 都安| 普陀区| 新乡市| 唐山市| 九龙城区| 班戈县| 海城市| 花莲市| 聂拉木县| 广宁县| 顺义区| 寿阳县| 延安市| 祁连县| 两当县| 晋州市| 马边| 乃东县| 太和县| 兴隆县| 高陵县| 湘阴县| 安达市| 大同市| 师宗县| 大城县| 德钦县| 屏南县| 临潭县| 石景山区| 柘荣县| 栖霞市| 怀来县| 新田县| 会东县| 惠东县| 扎兰屯市| 河东区| 本溪市|