简体   繁体   English

获取确切数量的Recyclerview项目以适合可用的屏幕高度

[英]Get Exact Number of Recyclerview Items to fit the available screen height

I am fetching results from the web to display it in the RecyclerView, in order to optimize the process, I wish to limit maximum results fetched from the web. 我正在从Web上获取结果以在RecyclerView中显示,为了优化流程,我希望限制从Web上获取的最大结果。

In order to limit the number of results, I need to know how many list items will be required to fill the entire screen. 为了限制结果的数量,我需要知道填充整个屏幕需要多少个列表项。 I have the height of each list item in dp, but I am not able to get the height of available space on screen so that I can divide screen height by height of each item (dp). 我具有dp中每个列表项的高度,但是我无法获得屏幕上可用空间的高度,因此无法将屏幕高度除以每个项目的高度(dp)。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/video_list_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context="com.bgbtech.gujaratirasoi.VideoListScreen">

     <android.support.v7.widget.RecyclerView
        android:id="@+id/video_list_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:visibility="gone" />

 </RelativeLayout>

So how to get the available height on the screen, excluding the actionbar 那么如何获得屏幕上的可用高度(不包括操作栏)

You can get screen size like this: 您可以这样获得屏幕尺寸:

Display display = getActivity().getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
int displayHeight = size.y;

You can get actionBar height like this 你可以像这样获得actionBar的高度

TypedValue typedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize,typedValue, true);
int actionBarHeight = getResources().getDimensionPixelSize(typedValue.resourceId);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据屏幕尺寸调整物品高度以适合其RecyclerView - Adjust items height to fit its RecyclerView according to screen size 如何在屏幕上显示确切数量的ListView项目? - How do I fit an exact number of ListView items on screen? 在Android屏幕上安装recyclerview项目 - Fit recyclerview items on android screen 使 recyclerView 项目适合屏幕 - Making recyclerView items fit the screen 如何在 RecyclerView 中显示确切的项目数量? - How to show exact number of items in RecyclerView? Android:在recyclerview中获取用户在屏幕上的确切位置 - Android: get the exact position on the screen that the user was at in a recyclerview 如何在 RecyclerView 或 ListView 项目视图中使用 layout_weight 来让等高的项目填满屏幕上的可用空间? - How can I use layout_weight in RecyclerView or ListView item view to have items of equal height fill up the available space on screen? RecyclerView + GridLayoutManager:调整项目大小以适应屏幕并保持比率 - RecyclerView + GridLayoutManager: Resizing items to fit the screen and preserve ratio 创建之前查找适合屏幕的RecyclerView项目数 - Find how many RecyclerView items fit screen before creation 如何在Android屏幕上安装Horizo​​ntal RecyclerView可滚动项? - How to fit Horizontal recyclerView scrollable items into screen in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM