如何网格视图更改列数运行? [英] How does Grid View change column number runtime?

查看:126
本文介绍了如何网格视图更改列数运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图改变GridView的列数。我称之为 setNumColumn() invalidateViews()更新视图。

I am trying to change gridView column number. I call setNumColumn() and invalidateViews() to update the view.

然而,在网格的单元格的宽度不会动态变化。我设置了 stretchMode =columnWidth中,但没有奏效。

However, the grid's cell width will not change dynamically. I set the stretchMode="columnWidth", but it didn't work.

推荐答案

问题解决了:

在网格视图中的子视图不重新计算其布局时,网格视图更改列上运行。

The child view in the grid view do not re-calculate its layout when the grid view changes the column on runtime.

在你BaseAdapter,你应该叫forceLayout()来计算其布局。

In your BaseAdapter, you should call forceLayout() to calculate its layout.

@Override
public View getView(final int position, View convertView,
        ViewGroup parent) {


    if (null == convertView) {
        convertView = mInflater.inflate(
                R.layout.mnm_customer_user_thumbnail, null);

        control.txtUserName = (TextView) convertView
                .findViewById(R.id.mnmTxtStudentName);
        control.image = (ImageView) convertView
                .findViewById(R.id.mnmImageStudent);
        control.imageCheckBox = (ImageView) convertView
                .findViewById(R.id.mnmImageCheckBox);
        control.mnmOuterBounder = (RelativeLayout) convertView
                .findViewById(R.id.mnmOuterBound);
        convertView.setTag(control);
    } else {
        convertView.forceLayout();
    }

...
...
...
...

感谢

这篇关于如何网格视图更改列数运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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