标签:android style blog io ar color sp for on
现在的界面是越做越长了,不知道你们会有什么绝招来对付这么长的界面,我还是利用listview或者GridView来结合Scrollview来合成。然后,问题来了,如果试这么开始的,总会有滑动冲突的现象产生。
那么,该何去何从呢,我也是见别人的参考做的。记下来,今后肯定用的多。
package com.ky.utills; import android.view.View; import android.view.ViewGroup; import android.widget.GridView; import android.widget.ListAdapter; import android.widget.ListView; public class Utility { public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); } public static void setGridViewHeightBasedOnChildren(GridView gridView, int num) { ListAdapter listAdapter = gridView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = 0; int count = 0; if (listAdapter.getCount() % num == 0) { count = listAdapter.getCount() / num; } else { count = listAdapter.getCount() / num + 1; } for (int i = 0; i < count; i++) { View listItem = listAdapter.getView(i, null, gridView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = gridView.getLayoutParams(); params.height = totalHeight + (gridView.getHeight() * ((count) - 1)); gridView.setLayoutParams(params); } }
,然后在Viewsetadapter后,加上这个就okay:
Utility.setListViewHeightBasedOnChildren(game_ListView);
完好,今天送给自己一句话:人活着一定要有意义
标签:android style blog io ar color sp for on
原文地址:http://www.cnblogs.com/Catherine-Brain/p/4137916.html