Java Code Examples for android.widget.listview#getPaddingBottom()

The following examples show how to use android.widget.listview#getPaddingBottom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentUnlocksCard.java    From WaniKani-for-Android with GNU General Public License v3.0 6 votes vote down vote up
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));
    }
}
 
Example 2
Source File: CriticalItemsCard.java    From WaniKani-for-Android with GNU General Public License v3.0 6 votes vote down vote up
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));
    }
}
 
Example 3
Source File: ViewUtil.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
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;
        }

    }
 
Example 4
Source File: UIUtils.java    From SimpleSmsRemote with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 5
Source File: TabularContextMenuUi.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: Utils.java    From biermacht with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: ViewUnit.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
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;
	}
}
 
Example 8
Source File: MainActivity.java    From TapUnlock with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: ListViewCapture.java    From ViewCapture with Apache License 2.0 4 votes vote down vote up
@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;
    }
}