Skip to content

Instantly share code, notes, and snippets.

@opatry
Last active October 30, 2017 08:10
Show Gist options
  • Save opatry/3ae1bee9c1cea1e8f6ce2378cd8aff58 to your computer and use it in GitHub Desktop.
Save opatry/3ae1bee9c1cea1e8f6ce2378cd8aff58 to your computer and use it in GitHub Desktop.
Using Android sample data `tools:showIn`, `tools:listitem`, `tools:...="@sample/data.json` for awesome layout preview
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
tools:showIn="@layout/myscreen">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@sample/mydata.json/items/icon"
tools:tint="@sample/mydata.json/items/icon_color"/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="@sample/mydata.json/items/label"/>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/mylistitem"/>
</android.support.constraint.ConstraintLayout>
{
"items": [
{
"label": "Foo",
"icon": "@drawable/ic_android_black_24dp",
"icon_color": "#ff0000"
},
{
"label": "Bar",
"icon": "@drawable/ic_star_black_24dp",
"icon_color": "#ffff00"
},
{
"label": "Zorg",
"icon": "@drawable/ic_account_circle_black_24dp",
"icon_color": "#ff00ff"
},
{
"label": "Quux",
"icon": "@drawable/ic_brush_black_24dp",
"icon_color": "#00ffff"
},
{
"label": "Garply",
"icon": "@drawable/ic_child_care_black_24dp",
"icon_color": "#0000ff"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment