How does Grid View change column number runtime?

前端 未结 3 1865
小鲜肉
小鲜肉 2021-01-28 18:10

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

However, the grid\'s cell width w

3条回答
  •  逝去的感伤
    2021-01-28 19:01

    Problem Solved:

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

    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();
        }
    
    ...
    ...
    ...
    ...
    

    Thanks

提交回复
热议问题