When I add the RecyclerView to the layout, it shows up as a blank screen. Is there a way, such as through the tools
namespace, to show a preview of the content of the RecyclerView?
问题:
回答1:
@oRRs is right !
I'm using Android Studio 1.4 RC2 and you can now specify any custom layout.
I tried a custom CardView and it works.
tools:listitem="@android:layout/simple_list_item_checked"
回答2:
tools
namespace enables design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources) It is really powerful feature that is developing and allows you not compile code every time to see changes
Example with GridLayoutManager
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="5"
tools:layoutManager="android.support.v7.widget.GridLayoutManager"
tools:listitem="@layout/item_video"
tools:orientation="horizontal"
tools:scrollbars="horizontal"
tools:spanCount="2" />
Another cool feature that was introduced in Android studio 3.0
is predefining a data through the tools attributes, to visualized easily your layout structure using tools:text="@tools:sample/last_names"
. For example your preview will looks like
Please read more here -
https://developer.android.com/studio/write/tool-attributes.html
https://youtu.be/Hx_rwS1NTiI?list=PLWz5rJ2EKKc-odHd6XEaf7ykfsosYyCKp&t=408
https://android.jlelse.eu/android-tools-attributes-listitem-sample-data-rocks-bbf49aaa9f07
回答3:
As of Android Studio 1.3.1 it shows default list items in the preview but it doesn't let yout specify your own yet. Hopefully, it will come.
回答4:
First, add the following line in your item XML to made a preview of your list while you edit your item:
tools:showIn="@layout/activity_my_recyclerview_item"
And them, add the following line in your RecyclerView XML to preview how your item will look in your list:
tools:listitem="@layout/adapter_item"