与GridView控件内滚动型机器人中存在的问题 [英] Problems with GridView inside ScrollView in android

查看:102
本文介绍了与GridView控件内滚动型机器人中存在的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我把里面的GridView的滚动型的机器人。 当我把GridView控件无法正常工作。

I'm trying I put the GridView inside ScrollView in android. When I put the GridView not work.

下面是布局。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scroll_home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout 
            android:id="@+id/layout_home" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">       

              <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/programacao_grid"
                android:numColumns="auto_fit"
                android:gravity="center"
                android:columnWidth="50dp"
                android:stretchMode="columnWidth"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_below="@+id/calendario_programacao"
             >       
            </GridView> 

    </RelativeLayout>

</ScrollView>

在许多搜索找到了答案,这是低于

After many search a found the answer and it is below

推荐答案

搜索之后,我发现这个项目链接< /一>: -

After search i found this project link:-

ExpandableHeightGridView

package xx.xxx.xx.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.GridView;

/**
 * ScrollViewの中のGridViewでも高さを可変にする<br>
 * http://stackoverflow.com/questions/8481844/gridview-height-gets-cut
 */

public class ExpandableHeightGridView extends GridView {

boolean expanded = false;

public ExpandableHeightGridView(Context context)
{
    super(context);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

public ExpandableHeightGridView(Context context, AttributeSet attrs,
        int defStyle)
{
    super(context, attrs, defStyle);
}

public boolean isExpanded()
{
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    // HACK! TAKE THAT ANDROID!
    if (isExpanded())
    {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded)
{
    this.expanded = expanded;
} }

layout.xml 文件:

<ScrollView
    android:id="@+id/sc_spots"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >


        <xx.xxx.xx.view.ExpandableHeightGridView
            android:id="@+id/spotsView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:horizontalSpacing="10dp"
            android:isScrollContainer="false"
            android:numColumns="5"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" />
 </ScrollView>

使用的GridView

mGridView = (ExpandableHeightGridView)
getView().findViewById(R.id.spotsView);
mGridView.setExpanded(true);
SpotsAdapter adapter = new SpotsAdapter(getActivity(),R.layout.spot_item,params);
mGridView.setAdapter(adapter);
adapter.notifyDataSetChanged();

这篇关于与GridView控件内滚动型机器人中存在的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆