本文整理匯總了Java中android.widget.ExpandableListAdapter.getChildrenCount方法的典型用法代碼示例。如果您正苦於以下問題:Java ExpandableListAdapter.getChildrenCount方法的具體用法?Java ExpandableListAdapter.getChildrenCount怎麽用?Java ExpandableListAdapter.getChildrenCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.ExpandableListAdapter
的用法示例。
在下文中一共展示了ExpandableListAdapter.getChildrenCount方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setExpandedListViewHeightBasedOnChildren
import android.widget.ExpandableListAdapter; //導入方法依賴的package包/類
public static void setExpandedListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) {
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
if (listAdapter == null) {
return;
}
View listItem = listAdapter.getChildView(groupPosition, 0, true, null,
listView);
listItem.measure(0, 0);
int appendHeight = 0;
for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) {
appendHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height += appendHeight;
listView.setLayoutParams(params);
}
示例2: setCollapseListViewHeightBasedOnChildren
import android.widget.ExpandableListAdapter; //導入方法依賴的package包/類
public static void setCollapseListViewHeightBasedOnChildren(ExpandableListView listView, int groupPosition) {
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
if (listAdapter == null) {
return;
}
View listItem = listAdapter.getChildView(groupPosition, 0, true, null,
listView);
listItem.measure(0, 0);
int appendHeight = 0;
for (int i = 0; i < listAdapter.getChildrenCount(groupPosition); i++) {
appendHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height -= appendHeight;
listView.setLayoutParams(params);
}
示例3: setListViewHeightBasedOnItems
import android.widget.ExpandableListAdapter; //導入方法依賴的package包/類
/**
* Sets ExpandableListView height dynamically based on the height of the items.
*
* @param expandablelistView to be resized
* @return true if the expandablelistView is successfully resized, false otherwise
*/
public static boolean setListViewHeightBasedOnItems(ExpandableListView expandablelistView) {
ExpandableListAdapter expandableListAdapter = expandablelistView.getExpandableListAdapter();
if (expandableListAdapter != null) {
int numberOfGroups = expandableListAdapter.getGroupCount();
int numberOfDividers = numberOfGroups;
// Get total height of all items of all group expanded
int totalItemsHeight = 0;
for (int groupPos = 0; groupPos < numberOfGroups; groupPos++) {
View item = expandableListAdapter.getGroupView(groupPos, expandablelistView.isGroupExpanded(groupPos), null, expandablelistView);
item.measure(0, 0);
totalItemsHeight += item.getMeasuredHeight();
if(expandablelistView.isGroupExpanded(groupPos)) {
totalItemsHeight += calculateHeightOfOneGroup(groupPos, expandableListAdapter, expandablelistView);
numberOfDividers += expandableListAdapter.getChildrenCount(groupPos);
}
}
// Get total height of all item dividers.
int totalDividersHeight = expandablelistView.getDividerHeight() * numberOfDividers;
// Set list height.
ViewGroup.LayoutParams params = expandablelistView.getLayoutParams();
params.height = totalItemsHeight + totalDividersHeight + 5;
expandablelistView.setLayoutParams(params);
expandablelistView.requestLayout();
return true;
} else {
return false;
}
}
示例4: calculateHeightOfOneGroup
import android.widget.ExpandableListAdapter; //導入方法依賴的package包/類
/**
* Calculate the height of an expanded group dynamically based on the height of the items.
*
* @param groupPos position of the current group
* @param expandableListAdapter adapter of the expandableList
* @param parent the parent that this view will eventually be attached to
* @return true if the listView is successfully resized, false otherwise
*/
public static int calculateHeightOfOneGroup(int groupPos, ExpandableListAdapter expandableListAdapter, ViewGroup parent) {
int numberOfItems = expandableListAdapter.getChildrenCount(groupPos);
// Get total height of all items in the group
int totalItemsHeight = 0;
for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
boolean lastItem = false;
if(itemPos == numberOfItems-1){
lastItem = true;
}
// Supprimer le if si on veut garder un truc générique. Ici, le if sert à gérer la cutom expandable en plus des expandables classiques
View item;
if(expandableListAdapter instanceof com.orange.ease.idunnololz.widgets.AnimatedExpandableListView.AnimatedExpandableListAdapter){
item = ((AnimatedExpandableListView.AnimatedExpandableListAdapter) expandableListAdapter).getRealChildView(groupPos, itemPos, lastItem, null, parent);
}else{
item = expandableListAdapter.getChildView(groupPos, itemPos, lastItem, null, parent);
}
item.measure(0, 0);
totalItemsHeight += item.getMeasuredHeight();
}
return totalItemsHeight;
}
示例5: updateExpandableListViewHeight
import android.widget.ExpandableListAdapter; //導入方法依賴的package包/類
/**
* To compute the expandable listview for a given group.
*
* @param listView ExpandableListView
* @param group group
*/
public static void updateExpandableListViewHeight(ExpandableListView listView,
int group) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(0, 0);
totalHeight += groupItem.getMeasuredHeight();
if (((listView.isGroupExpanded(i)) && (i != group))
|| ((!listView.isGroupExpanded(i)) && (i == group))) {
for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
View listItem = listAdapter.getChildView(i, j, false, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
示例6: setListViewHeight
import android.widget.ExpandableListAdapter; //導入方法依賴的package包/類
public static void setListViewHeight(ExpandableListView listView, int group) {
ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
MeasureSpec.AT_MOST);
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += groupItem.getMeasuredHeight();
if (((listView.isGroupExpanded(i)) && (i != group))
|| ((!listView.isGroupExpanded(i)) && (i == group))) {
for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
View listItem = listAdapter.getChildView(i, j, false, null,
listView);
listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight();
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
int height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
if (height < 10)
height = 200;
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();
}