[英]Dynamic height of row in Gridview
I'm creating an application which is similar with Calendar. 我正在创建一个与Calendar类似的应用程序。 However, I have an issue when display the calendar.
但是,显示日历时出现问题。 I want the height of the gridview fixed with the height of the layout.
我希望gridview的高度与布局的高度固定。 How can I do that?
我怎样才能做到这一点?
Thanks! 谢谢!
public class Helper {
public static void getListViewSize(ListView myListView) {
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
// do nothing return null
return;
}
// set listAdapter in loop for getting final size
int totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
// setting listview item in adapter
ViewGroup.LayoutParams params = myListView.getLayoutParams();
params.height = totalHeight
+ (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
myListView.setLayoutParams(params);
// print height of adapter on log
Log.i("height of listItem:", String.valueOf(totalHeight));
}
}
May be same thing you can apply for gridview 您可以申请gridview可能是同一件事
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.