Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling ListView preview items number in Android Studio

I have a ListView which would usually only display 1-3 items at runtime, but Android Studio fills it with 24, making it overtake the whole layout. If I want to see the rest of the layout I have to either comment it out or set its visibility to gone. Is there a way I can make Android Studio only render a couple of items so my other views in the layout will be visible in the designer?

like image 425
svbnet Avatar asked Mar 22 '15 21:03

svbnet


People also ask

What is listview in Android?

Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database.

How to display scrollable list of items in Android using listview?

List of scrollable items can be displayed in Android using ListView. It helps you to displaying the data in the form of a scrollable list. Users can then select any list item by clicking on it.

How to get selected selected listview clicked item on Android?

Get listview clicked item on android. Application builder can get selected list item value through setOnItemClickListener() function. By selecting list array element developer can perform various task on it like open a new list view or any target page.

How do you insert an item into a list in Android?

List items are automatically inserted to a list using an Adapter that pulls the content from a source such as an arraylist, array or database. ListView in Android Studio: Listview is present inside Containers. From there you can drag and drop on virtual mobile screen to create it.


1 Answers

I was facing the same issue and I solved it by adding this to the ListView definition:

tools:layout_height="350dip"

If you're using a RecyclerView, you could do it much better:

tools:itemCount="3"

Both arguments are only applied in the Android Studio preview, not in the app itself, see https://developer.android.com/studio/write/tool-attributes.

like image 198
mivola Avatar answered Sep 18 '22 13:09

mivola