当前位置: 移动技术网 > 移动技术>移动开发>Android > Android开发之机顶盒上gridview和ScrollView的使用详解

Android开发之机顶盒上gridview和ScrollView的使用详解

2019年07月24日  | 移动技术网移动技术  | 我要评论

最近在机顶盒上做一个gridview,

其焦点需要在item的子控件上,但gridview的焦点默认在item上,通过
android:descendantfocusability="afterdescendants"

<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可以一直让子控件获得焦点,并且可以顺利滚动。

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焦点等级很高。

以上内容给大家介绍了android开发之机顶盒上gridview和scrollview的使用详解,希望对大家有所帮助!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网