How to put new placeholder resources into Android Studio project (“tools:sample” resources)?

前端 未结 4 1189
青春惊慌失措
青春惊慌失措 2020-12-13 01:09

Background

Sometimes, you wish to put some placeholders to be shown only on the IDE, in layout files.

As an example, you can use this:

<         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-13 02:00

    On my side I tried to use a image file as a placeholder for an Imageview using tools:src="...": I did put my PNG file in a sampledatasubdirectory but it either wouldn't show or appear as a broken image.

    After a bit of fiddlings I found something that fixed my issue:

    • create a sampledata subdirectory named: drawable
    • place your png/jpg file in this directory and append the file name with "_drawable". Ex: image.png -> image_drawable.png

    Only then did the placeholder showed up. You can create subdirectories from drawable as you see fit to keep your sample images organized, but the important thing seems to be that drawable remains a parent directory.

    I do not have any documentation or sources to back me up, but I figure it could be useful for other in the same situation.

提交回复
热议问题