18

Is there a way to get Android Studio's layout preview screen to populate a GridView or ListView with placeholder views of the actual runtime layout?

In other words, I don't want to see a grid of "Item 1/ Sub Item 1" views, I want to be able to set @layout/foo somewhere and have it show up in there.

sigmabeta
  • 1,174
  • 1
  • 12
  • 28

1 Answers1

55

From graphical editor:

Adding list item preview

From xml:

<GridView
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="2"
        tools:listitem="@layout/grid_item"/>

Note: pay attention to this isse: https://stackoverflow.com/a/12188118/624706

Community
  • 1
  • 1
Sergii Pechenizkyi
  • 22,227
  • 7
  • 60
  • 71
  • Thanks! This is exactly what I was looking for. Do you know if there is a similar function for spinners (since they appear to be similar in implementation to ListView, though the right-click context menu does not appear to contain the same option)? edit: Nevermind, the XML works for Spinners as well, I just made a typo when I tried it out. Thanks again! – sigmabeta Nov 08 '13 at 18:28
  • 2
    on my version, I don't have a context menu, and this functionality requires `android:id` to be set – nik.shornikov Feb 08 '15 at 01:47