Android Studio layout previews for Listview + Grid

2020-06-08 02:23发布

问题:

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.

回答1:

From graphical editor:

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