Use of the gridview + ScrollView on the set-top box ., Gridviewscrollview

Source: Internet
Author: User

Use of the gridview + ScrollView on the set-top box ., Gridviewscrollview

Recently, I made a gridview on the set-top box,

The focus must be on the item child control, but the focus of the gridview is on the item by default.

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>

 

Allows the child control of the gridview to get the focus. However, after this attribute is added, the gridview will become unable to scroll. Then I added a ScrollView TO THE gridview,

However, since both of them have a scroll bar, I overwrite a gridview to make it disappear. Finally, the gridview is successfully enabled to keep the child control focused and smooth.

Scroll.

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: My layout is absolute, and there is nothing special about the item layout and the adapter code. The CheckBox focus level is very high.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.