Java Code Examples for android.widget.listview#getPaddingTop()
The following examples show how to use
android.widget.listview#getPaddingTop() .
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: CriticalItemsCard.java From WaniKani-for-Android with GNU General Public License v3.0 | 6 votes |
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 2
Source File: RecentUnlocksCard.java From WaniKani-for-Android with GNU General Public License v3.0 | 6 votes |
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 3
Source File: ListPosition.java From Dashchan with Apache License 2.0 | 6 votes |
public static ListPosition obtain(ListView listView) { int position = listView.getFirstVisiblePosition(); int y = 0; Rect rect = new Rect(); int paddingTop = listView.getPaddingTop(), paddingLeft = listView.getPaddingLeft(); for (int i = 0, count = listView.getChildCount(); i < count; i++) { View view = listView.getChildAt(i); view.getHitRect(rect); if (rect.contains(paddingLeft, paddingTop)) { position += i; y = rect.top - paddingTop; break; } } return new ListPosition(position, y); }
Example 4
Source File: SwipeRefreshListFragment.java From soas with Apache License 2.0 | 5 votes |
/** * Utility method to check whether a {@link ListView} can scroll up from it's current position. * Handles platform version differences, providing backwards compatible functionality where * needed. */ private static boolean canListViewScrollUp(ListView listView) { if (SdkUtils.hasIceCreamSandwich()) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(listView, -1); } else { // Pre-ICS we need to manually check the first visible item and the child view's top // value return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0 || listView.getChildAt(0).getTop() < listView.getPaddingTop()); } }
Example 5
Source File: SwipeRefreshListFragment.java From android-SwipeRefreshListFragment with Apache License 2.0 | 5 votes |
/** * Utility method to check whether a {@link ListView} can scroll up from it's current position. * Handles platform version differences, providing backwards compatible functionality where * needed. */ private static boolean canListViewScrollUp(ListView listView) { if (android.os.Build.VERSION.SDK_INT >= 14) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(listView, -1); } else { // Pre-ICS we need to manually check the first visible item and the child view's top // value return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0 || listView.getChildAt(0).getTop() < listView.getPaddingTop()); } }
Example 6
Source File: MainActivity.java From TapUnlock with Apache License 2.0 | 5 votes |
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 7
Source File: SwipeRefreshWidget.java From physical-web with Apache License 2.0 | 5 votes |
@Override public boolean canChildScrollUp() { // The real child maps cares about is the list, so check if that can scroll. ListView target = (ListView) findViewById(android.R.id.list); return target.getChildCount() > 0 && (target.getFirstVisiblePosition() > 0 || target.getChildAt(0).getTop() < target.getPaddingTop()); }
Example 8
Source File: SwipeRefreshListFragment.java From catnut with MIT License | 5 votes |
/** * Utility method to check whether a {@link ListView} can scroll up from it's current position. * Handles platform version differences, providing backwards compatible functionality where * needed. */ private static boolean canListViewScrollUp(ListView listView) { if (android.os.Build.VERSION.SDK_INT >= 14) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(listView, -1); } else { // Pre-ICS we need to manually check the first visible item and the child view's top // value return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0 || listView.getChildAt(0).getTop() < listView.getPaddingTop()); } }
Example 9
Source File: ViewUnit.java From Dashchan with Apache License 2.0 | 5 votes |
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 10
Source File: Utils.java From biermacht with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: TabularContextMenuUi.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: UIUtils.java From SimpleSmsRemote with MIT License | 5 votes |
/** * 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 13
Source File: FragmentSocialTimeline.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
private static boolean canListViewScrollUp(ListView listView) { if (android.os.Build.VERSION.SDK_INT >= 14) { // For ICS and above we can call canScrollVertically() to determine this return ViewCompat.canScrollVertically(listView, -1); } else { // Pre-ICS we need to manually check the first visible item and the child view's top // value return listView.getChildCount() > 0 && (listView.getFirstVisiblePosition() > 0 || listView.getChildAt(0).getTop() < listView.getPaddingTop()); } }
Example 14
Source File: ViewUtil.java From Orin with GNU General Public License v3.0 | 5 votes |
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 15
Source File: UiUtil.java From android-file-chooser with Apache License 2.0 | 4 votes |
public static int getListYScroll(@NonNull final ListView list) { View child = list.getChildAt(0); return child == null ? -1 : list.getFirstVisiblePosition() * child.getHeight() - child.getTop() + list.getPaddingTop(); }
Example 16
Source File: ArtistDetailActivity.java From Orin with GNU General Public License v3.0 | 4 votes |
public void setHeightofListViewBasedOnContent(ListView listView) { ListAdapter mAdapter = listView.getAdapter(); int totalHeight = 0; for (int i = 0; i < mAdapter.getCount(); i++) { totalHeight += getResources().getDimension(R.dimen.item_list_height); Log.w("HEIGHT" + i, String.valueOf(totalHeight)); } totalHeight = totalHeight + (listView.getDividerHeight() * (mAdapter.getCount() - 1)) + listView.getPaddingTop(); ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight; listView.setLayoutParams(params); listView.requestLayout(); }
Example 17
Source File: ListViewCapture.java From ViewCapture with Apache License 2.0 | 4 votes |
@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; } }