Tools: text for RecyclerView elements

I know that when you install

tools:text="Sample text"

inside TextView, you will see sample text in preview mode in Android Studio, but not in the application itself. I would like to do this for items in RecyclerView, but it seems like I can't do it. Here is what I have done so far:

In RecyclerView (named content_feed):

tools:listitem="@layout/cell_feed"

In the cell (name cell_feed):

tools:showIn="@layout/content_feed"

Wsbhq.png

Here are the files xml:

cell_feed.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_feed_cell"
    android:layout_marginLeft="@dimen/margin_feed_cell"
    android:layout_marginRight="@dimen/margin_feed_cell"
    android:orientation="horizontal"
    tools:showIn="@layout/content_feed">

    <LinearLayout
        android:id="@+id/timeLayouts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="@dimen/alpha_feed_secondary_text"
            android:textSize="@dimen/size_feed_secondary_text"
            android:id="@+id/startTimeText"
            tools:text="8:00 AM"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="@dimen/alpha_feed_secondary_text"
            android:textSize="@dimen/size_feed_secondary_text"
            android:id="@+id/endTimeText"
            tools:text="10:00 AM"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/margin_feed_cell_text"
        android:layout_toRightOf="@+id/timeLayouts"
        android:layout_centerVertical="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_bottom_feed_cell_title"
            android:textSize="@dimen/size_feed_cell_title"
            android:textStyle="bold"
            android:id="@+id/titleText"
            tools:text="Event title"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="@dimen/alpha_feed_secondary_text"
            android:textSize="@dimen/size_feed_secondary_text"
            android:id="@+id/captionText"
            tools:text="Event caption"/>
    </LinearLayout>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="@dimen/margin_feed_cell_text"
        tools:text=""/>
</RelativeLayout>

content_feed.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/feedRecycler"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:listitem="@layout/cell_feed"
    tools:showIn="@layout/activity_feed"/>
+6
source share
1 answer

, , " " Google I/O 2017. , Tor Norbye .

, :

tools:text="@tools:sample/lorem"

:

Layout preview with lorem ipsum sample text

:

tools:text="@tools:sample/date_day_of_week"

:

Layout preview with tools sample text

. , . New | Sample Data directory.

, , activity_log.json sampledata :

{
    "activities" : [
     {
       "icon": "@sample/activity_icons[ic_biking.png]",
       "description": "Biking",
       "location" : "Pleasant Hill, CA",
       "distance": "48 miles",
       "date": "Yesterday"
     },
     // other items here
    ]
}

:

tools:src="@sample/activity_log.json/activities/icon"
tools:src="@sample/activity_log.json/activities/distance"

:

Layout preview with custom sample data

. " " .

+18

Source: https://habr.com/ru/post/1017372/


All Articles