Android可扩展列表视图自定义子视图onSizeChanged始终为零

时间:2014-07-09 10:52:11

标签: android android-layout expandablelistview android-view

ExpandableListView的getChildView最初是从arraylist中读取的文本列表中膨胀的。如果选择了某个项目(单选模式),那么我想将子视图更改为自定义视图,例如图像。

@Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        if (convertView != null) {
            Log.e("EffectsAdapter", "convertView != null");
            if (getClicked(groupPosition, childPosition)) {
                Log.e(TAG, "getClicked true");
                CustomView cv= new CustomView (mInflator.getContext());
                cv.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT));

        //      ProgressBar pgbar = (ProgressBar)convertView.findViewById(R.id.progressBar1);
                return cv;//convertView;

            }
            convertView = mInflator.inflate(R.layout.lv_child, null);

        }

如果我在 xml 中使用CustomView,包含在LinearLayout中,那么高度和重量都是WRAP_CONTENT

但是如果像上面的代码一样实例化,视图的onSizeChanged总是会收到高度为零,为什么?

protected void onSizeChanged(int width, int height, int oldwid, int oldhght) {
        Log.e(TAG,"onsizeChanged w = "+String.valueOf(width)+" h= "+String.valueOf(height)
                +"oldw = "+String.valueOf(oldwid)+" oldh = "+String.valueOf(oldhght));
        mWidth = width;
        mHeight = height;
        // initialize();
    }

1 个答案:

答案 0 :(得分:0)

同样的事发生在我身上。我通过在layout的xml中将视图的layout_height从wrap_content更改为match_parent来修复它