Как сделать высоту от recyclerView
до wrap_content
так, чтобы в ней не было полосы прокрутки. Я хочу сделать ее высотой до тех пор, пока содержимое и я не хочу, чтобы в ней была полоса прокрутки, но когда я пытаюсь добавьте содержимое в recyclerView
, однако он помещает там прокрутку и фиксирует высоту просмотра recycler. Пожалуйста, помогите мне в решении этого.Как сделать высоту recyclerview для wrap_content?
-7
A
ответ
1
Что нужно сделать, чтобы динамически установить высоту вашего RecyclerView, я ранее делал это, но в ListView.
Если вы можете перейти от RecyclerView к ListView вы можете использовать этот метод, в противном случае оставьте комментарий, и я буду корректировать код для RecyclerView:
/**
* Sets ListView height dynamically based on the height of the items.
*
* @param listView to be resized
* @return true if the listView is successfully resized, false otherwise
*/
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);
// Set list height.
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalItemsHeight + totalDividersHeight;
listView.setLayoutParams(params);
listView.requestLayout();
return true;
} else {
return false;
}
}
Это делает RecyclerView usless ... просто использовать LinearLayout .. . – Selvin
Создайте макет для элемента и добавьте его диаманно. – akshay
не понимаю. Пожалуйста, дополните. –