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
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答