最近在機頂盒上做一個gridview,
其焦點需要在item的子控件上,但gridview的焦點默認在item上,通過
android:descendantfocusability="afterdescendants"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<scrollview android:id= "@+id/scroll_content" android:layout_width= "1740.0px" android:layout_height= "600.0px" android:layout_x= "81.0px" android:layout_y= "258.0px" > <com.hysmarthotel.view.mygridview android:id= "@+id/lightview" android:layout_width= "match_parent" android:layout_height= "match_parent" android:descendantfocusability= "afterdescendants" android:horizontalspacing= "58dp" android:numcolumns= "4" android:scrollbars= "none" android:stretchmode= "columnwidth" android:verticalspacing= "80dp" /> </scrollview> |
可以讓gridview的子控件獲得焦點。但是加了這個屬性之后,gridview就會變得無法滾動,后來我就給gridview加了一個scrollview,
但由于它們兩個都有滾動條,所以我重寫了一個gridview,讓其滾動條消失。終于成功地讓gridview可以一直讓子控件獲得焦點,并且可以順利滾動。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package com.hysmarthotel.view; import android.content.context; import android.util.attributeset; import android.widget.gridview; public class mygridview extends gridview { public mygridview(context context, attributeset attrs) { super (context, attrs); } public mygridview(context context) { super (context); } public mygridview(context context, attributeset attrs, int defstyle) { super (context, attrs, defstyle); } @override public void onmeasure( int widthmeasurespec, int heightmeasurespec) { int expandspec = measurespec.makemeasurespec( integer.max_value >> 2 , measurespec.at_most); super .onmeasure(widthmeasurespec, expandspec); } } |
ps:我的布局是絕對布局,以及關于item的布局和adapter的代碼沒什么特別的。checkbox焦點等級很高。
以上內(nèi)容給大家介紹了android開發(fā)之機頂盒上gridview和scrollview的使用詳解,希望對大家有所幫助!