{
  "$type": "site.standard.document",
  "canonicalUrl": "https://segunfamisa.com/posts/android-studio-design-time-attributes",
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreigb2pqggv5thrhv7o5fstliua3blqwwa4p4m4anrmuksvw36r5wbe"
    },
    "mimeType": "image/png",
    "size": 18224
  },
  "description": "Android Studio tip on using designtime attributes to preview layout designs",
  "path": "/posts/android-studio-design-time-attributes",
  "publishedAt": "2016-09-08T19:42:45.000Z",
  "site": "at://did:plc:a5mekodp4afxadlpr4hp2wci/site.standard.publication/3mm2oa7vz5327",
  "tags": [
    "android",
    "tip",
    "android studio"
  ],
  "textContent": "This is a short tip for Android Studio users. Many people know this, but I thought to still\nshare for those that don't know.\n\nAs developers, when we're building a UI layout in Android, it's common desire to want to preview what we're designing right?\n\nWe usually want to add that sample data, like android:text=\"Test Test\" to see how exactly it will look in our layout. Many times, we forget to remove such sample data.\nIt's even more stressful when you're building a list. You have to run the app to see what your list looks like.\n\nWell, designtime attributes are here to help.\n\nDesigntime attributes? What are they?\nDesigntime attributes are attributes that are used only in rendering the Android studio layout preview, they have no impact at runtime.\nDesigntime attributes aren't new in Android studio. They've been around since Android Studio 0.2.11.\n\nDesigntime attributes are specified by the use of the tools namespace in Android XML layouts.\n\nUsing designtime attributes\n\na. Declare tools namespace.\nTo use the designtime attributes, you need to first declare the tools namespace within the root tag of your layout. Your layout will look something like:\n\nAll tools attributes get stripped out at compile time by AAPT, and that's how they have no effect at runtime.\n\nb. Replace android namespace with tools\nNow that you have declared the namespace, you can replace almost any android xml attribute with tools, for the designtime.\n\nFor example, let's say we wanted to test our text wrapping and see how our textview would look with a very long text, we would do something like:\n\nNote the tools:text attribute we used instead of the usual android:text\n\nInteresting uses with listviews and recycler views\nNow, let's look at further examples of designtime attributes.\n\n1. ListView\nYou can use designtime attributes to preview what the list will look like if you've designed your list item, using the listitem attribute. For example:\n\n2. RecyclerView\nThanks to Efe for showing me this one.\n\nPoints to note about designtime attributes\n    It works ONLY with Android framework attributes. That is, it doesn't work with custom attributes yet.\n    You can use them together with regular layout android attributes. For example:\n\n    They only work within Android layout files. You can't use designtime attributes in menus, drawables, etc.\n\nReferences and further reading\n   http://tools.android.com/tips/layout-designtime-attributes\n  * http://tools.android.com/tech-docs/tools-attributes\n\nIf you have any comments/suggestions or corrections, or you want to share your use of designtime attributes, feel free to drop a comment below or tweet at me.\n\nPlease share if you found this useful.\n\nThanks for reading.\n\nCheers,\n\nSegun.",
  "title": "Android studio layout preview with tools designtime attributes"
}