android.widget.ListView#getPaddingBottom ( )源码实例Demo

下面列出了android.widget.ListView#getPaddingBottom ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: WaniKani-for-Android   文件: RecentUnlocksCard.java
public int setRecentUnlocksHeightBasedOnListView(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();

    if (listAdapter == null) {
        return (int) pxFromDp(550);
    } else {

        int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            if (listItem instanceof ViewGroup) {
                listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            }
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        totalHeight += mCardTitle.getMeasuredHeight();
        totalHeight += pxFromDp(16); // Add the paddings as well
        totalHeight += pxFromDp(48); // Add the more items button

        return totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    }
}
 
源代码2 项目: WaniKani-for-Android   文件: CriticalItemsCard.java
public int setCriticalItemsHeightBasedOnListView(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();

    if (listAdapter == null) {
        return (int) pxFromDp(550);
    } else {

        int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            if (listItem instanceof ViewGroup) {
                listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            }
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        totalHeight += mCardTitle.getMeasuredHeight();
        totalHeight += pxFromDp(32); // Add the paddings as well

        return totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    }
}
 
源代码3 项目: Orin   文件: ViewUtil.java
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;
        }

    }
 
源代码4 项目: SimpleSmsRemote   文件: UIUtils.java
/**
 * Set ListView height dynamically based on the height of the items.
 *
 * @param listView to be resized
 * @see <a href="http://stackoverflow.com/questions/1778485/android-listview-display-all-available-items-without-scroll-with-static-header">stackoverflow answer</a>
 */
public static void SetListViewHeightBasedOnItems(ListView listView) {

    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
        throw new RuntimeException("an adapter must be set before list view can be resized");

    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);

    //get vertical padding
    int paddingVertical = listView.getPaddingTop() + listView.getPaddingBottom();

    // Set list height.
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalItemsHeight + totalDividersHeight + paddingVertical;
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
源代码5 项目: 365browser   文件: TabularContextMenuUi.java
/**
 * To save time measuring the height, this method gets an item if the height has not been
 * previous measured and multiplies it by count of the total amount of items. It is fine if the
 * height too small as the ListView will scroll through the other values.
 * @param listView The ListView to measure the surrounding padding.
 * @param listAdapter The adapter which contains the items within the list.
 * @return Returns the combined height of the padding of the ListView and the approximate height
 *         of the ListView based off the an item.
 */
private int measureApproximateListViewHeight(
        ListView listView, BaseAdapter listAdapter, int maxCount) {
    int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
    if (mMenuItemHeight == 0 && !listAdapter.isEmpty()) {
        View view = listAdapter.getView(0, null, listView);
        view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        mMenuItemHeight = view.getMeasuredHeight();
    }
    return totalHeight + mMenuItemHeight * maxCount;
}
 
源代码6 项目: biermacht   文件: Utils.java
/**
 * This method adjusts the height of the given listView to match the combined height of all if its
 * children and the dividers between list items.  This is used to set the height of the mash step
 * list such that it does not scroll, since it is encompassed by a ScrollView.
 *
 * @param listView
 *         ListView to adjust.
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
  ListAdapter listAdapter = listView.getAdapter();
  if (listAdapter == null) {
    return;
  }

  int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
  int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
  View view = null;
  for (int i = 0; i < listAdapter.getCount(); i++) {
    view = listAdapter.getView(i, view, listView);

    view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);

    if (i == 0) {
      view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
      //totalHeight += view.getMeasuredHeight();
    }

    totalHeight += view.getMeasuredHeight();
  }
  ViewGroup.LayoutParams params = listView.getLayoutParams();
  params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
  listView.setLayoutParams(params);
  listView.requestLayout();
}
 
源代码7 项目: Dashchan   文件: ViewUnit.java
boolean handlePostForDoubleClick(final View view) {
	final PostViewHolder holder = ListViewUtils.getViewHolder(view, PostViewHolder.class);
	if (holder != null) {
		if (holder.comment.getVisibility() != View.VISIBLE || holder.comment.isSelectionEnabled()) {
			return false;
		}
		long t = System.currentTimeMillis();
		long timeout = holder.comment.getPreferredDoubleTapTimeout();
		if (t - holder.lastCommentClick > timeout) {
			holder.lastCommentClick = t;
		} else {
			final ListView listView = (ListView) view.getParent();
			final int position = listView.getPositionForView(view);
			holder.comment.startSelection();
			int padding = holder.comment.getSelectionPadding();
			if (padding > 0) {
				final int listHeight = listView.getHeight() - listView.getPaddingTop() -
						listView.getPaddingBottom();
				listView.post(() -> {
					int end = holder.comment.getSelectionEnd();
					if (end >= 0) {
						Layout layout = holder.comment.getLayout();
						int line = layout.getLineForOffset(end);
						int count = layout.getLineCount();
						if (count - line <= 4) {
							listView.setSelectionFromTop(position, listHeight - view.getHeight());
						}
					}
				});
			}
		}
		return true;
	} else {
		return false;
	}
}
 
源代码8 项目: TapUnlock   文件: MainActivity.java
public static void updateListViewHeight(ListView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();

    if (myListAdapter == null)
        return;

    // Get listView height
    int totalHeight = myListView.getPaddingTop() + myListView.getPaddingBottom();
    int adapterCount = myListAdapter.getCount();

    for (int i = 0; i < adapterCount; i++) {
        View listItem = myListAdapter.getView(i, null, myListView);

        if (listItem instanceof ViewGroup) {
            listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                                                ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    // Change height of listView
    ViewGroup.LayoutParams paramsList = myListView.getLayoutParams();
    paramsList.height = totalHeight + (myListView.getDividerHeight() * (adapterCount - 1));
    myListView.setLayoutParams(paramsList);
}
 
源代码9 项目: ViewCapture   文件: ListViewCapture.java
@Override
public Bitmap capture(@NonNull ListView listView) {
    List<View> viewList = new ArrayList<>();
    try {
        ListAdapter adapter = listView.getAdapter();
        Drawable dividerDrawable = listView.getDivider();
        Drawable backgroundDrawable = listView.getBackground();
        int dividerHeight = listView.getDividerHeight();
        int itemsCount = adapter.getCount();
        int allHeight = listView.getPaddingTop() + listView.getPaddingBottom();
        int allWidth = listView.getMeasuredWidth() + listView.getPaddingLeft() + listView.getPaddingRight();
        for (int i = 0; i < adapter.getCount(); i++) {
            View childView = adapter.getView(i, null, listView);
            childView.measure(
                    View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY),//
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
            childView.setDrawingCacheEnabled(true);
            childView.buildDrawingCache();
            viewList.add(childView);
            allHeight += childView.getMeasuredHeight();
        }
        allHeight += (itemsCount - 1) * dividerHeight;
        Bitmap bigBitmap = Bitmap.createBitmap(allWidth, allHeight, Bitmap.Config.RGB_565);
        Canvas bigCanvas = new Canvas(bigBitmap);
        Paint paint = new Paint();
        int iHeight = listView.getPaddingTop();
        final Rect bounds = new Rect();
        bounds.set(0, 0, allWidth, allHeight);
        backgroundDrawable.setBounds(bounds);
        backgroundDrawable.draw(bigCanvas);
        for (int i = 0; i < viewList.size(); i++) {
            View view = viewList.get(i);
            Bitmap bmp = view.getDrawingCache();
            bigCanvas.drawBitmap(bmp, listView.getPaddingLeft(), iHeight, paint);
            iHeight += bmp.getHeight();
            if (i < viewList.size() - 1 && dividerHeight > 0 && dividerDrawable != null) {
                bounds.set(0, iHeight, allWidth, iHeight + dividerHeight);
                dividerDrawable.setBounds(bounds);
                dividerDrawable.draw(bigCanvas);
                iHeight += dividerHeight;
            }
            view.setDrawingCacheEnabled(false);
            view.destroyDrawingCache();
            bmp.recycle();
            bmp = null;
        }
        report(bigBitmap);
        return bigBitmap;
    } finally {
        viewList.clear();
        viewList = null;
    }
}