【发布时间】:2016-05-01 08:49:09
【问题描述】:
我想实现 Fig-1,但我卡在 Fig-2,无法将完整的 gridview 视为 Listview 的标题。
如您所见,gridview 没有完全显示并隐藏在图 2 中的 Listview 后面
网格视图 xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/gridview"
android:numColumns="2"
android:stretchMode="columnWidth"
android:cacheColorHint="#ffffffff"
android:gravity="center"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
列表视图 xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<ListView
android:id="@+id/listview"
android:scrollbars="vertical"
android:background="#fff"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>
片段代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view=inflater.inflate(R.layout.fragmentpage_layout, null);
listView=(ListView)view.findViewById(R.id.listview);
header=inflater.inflate(R.layout.gridview_layout,null);
gridView=(GridView)header.findViewById(R.id.gridview);
listView.addHeaderView(header);
gridViewAdapter=new CustomGridViewAdapter(getActivity(),images,toptexts, bottomtexts);
listViewAdapter=new CustomListViewAdapter(getActivity(),images,toptexts,bottomtexts);
gridView.setAdapter(gridViewAdapter);
listView.setAdapter(listViewAdapter);
return view;
}
提前致谢。
【问题讨论】:
-
提供 xml 以便我们提供帮助。
-
因为你提到了高度,所以只需最小化高度并检查
-
我添加了xml文件
-
@AshishShukla 在调用 setAdater 后获取 gridview 计算 gridview 的高度并在布局参数中设置为高度
-
其实你不需要手动计算尺寸,你可以通过覆盖网格视图的onmeasure方法来完成。请检查链接以获取更多信息。 stackoverflow.com/a/22727503/3257178
标签: android listview android-gridview