GridView 填充后看不见内容,设置了大小也是显示不出来
原来是单独在一个xml只写一个GrideView,啥也没有了,然后inflate一下动态添加
<com.pggmall.origin.view.gridview.MyGridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginLeft="6.0dip"
android:layout_marginRight="6.0dip"
android:animateLayoutChanges="true"
android:clipToPadding="true"
android:columnWidth="100.0dip"
android:horizontalSpacing="8.0dip"
android:numColumns="3"
android:scrollbarStyle="outsideOverlay"
android:stretchMode="columnWidth"
android:verticalSpacing="8.0dip" />
这样就会出现测量布局大小都是为空的状态
给其套一层父类就可以正常显示了
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.pggmall.origin.view.gridview.MyGridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginLeft="6.0dip"
android:layout_marginRight="6.0dip"
android:animateLayoutChanges="true"
android:clipToPadding="true"
android:columnWidth="100.0dip"
android:horizontalSpacing="8.0dip"
android:numColumns="3"
android:scrollbarStyle="outsideOverlay"
android:stretchMode="columnWidth"
android:verticalSpacing="8.0dip" />
</RelativeLayout>
填充是代码:
void initAllView(View view) {
secondCate = (LinearLayout) view.findViewById(R.id.secondCate);
if (firstList.get(index_).getSecondList().isEmpty()) return;
for (int i=0 ;i<firstList.get(index_).getSecondList().size(); i++) {
List<CategorySecond> secList_ = firstList.get(index_).getSecondList();
RelativeLayout title = (RelativeLayout) inflater.inflate(R.layout.correcting3_pggmall_cate_gridview_title, null);
secondCate.addView(title);
RelativeLayout myGridViewPr = (RelativeLayout) inflater.inflate(R.layout.correcting3_pggmall_cate_gridview, null);
GridView myGridView = (GridView) myGridViewPr.findViewById(R.id.gridView);
secondCate.addView(myGridViewPr);
TextView secondTitle = (TextView) title.findViewById(R.id.secondTitle);
secondTitle.setText(secList_.get(i).getSecName());
MyAdapter gridAdapter = new MyAdapter(secList_.get(i).getThirdList());
myGridView.setAdapter(gridAdapter);
gridAdapter.notifyDataSetChanged();
}
}