本文整理汇总了Java中android.widget.ListView.getPaddingBottom方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.getPaddingBottom方法的具体用法?Java ListView.getPaddingBottom怎么用?Java ListView.getPaddingBottom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ListView
的用法示例。
在下文中一共展示了ListView.getPaddingBottom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAdapterHeight
import android.widget.ListView; //导入方法依赖的package包/类
public static void setAdapterHeight(ListView listView){
android.widget.ListAdapter listAdapter = listView.getAdapter();//1、获取adapter
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0,j =listAdapter.getCount(); i < j ; i++) { //2、算出没一个item高度总和
View listItem = listAdapter.getView(i , null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params=listView.getLayoutParams();
params.height = totalHeight + listView.getPaddingBottom() //3、加上listview自身每行间距属性
+ listView.getPaddingTop()
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);//4、重新设置高
}
示例2: setListViewHeightBasedOnItems
import android.widget.ListView; //导入方法依赖的package包/类
public static boolean setListViewHeightBasedOnItems(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter != null) {
int numberOfItems = listAdapter.getCount();
// Get total height of all items.
int totalItemsHeight = 0;
for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
View item = listAdapter.getView(itemPos, null, listView);
item.measure(0, 0);
totalItemsHeight += item.getMeasuredHeight();
}
// Get total height of all item dividers.
int totalDividersHeight = listView.getDividerHeight() *
(numberOfItems - 1);
int topPAdding = listView.getPaddingTop();
int bottomPadding = listView.getPaddingBottom();
// Set list height.
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalItemsHeight + totalDividersHeight + topPAdding + bottomPadding;
listView.setLayoutParams(params);
listView.requestLayout();
return true;
} else {
return false;
}
}