how to select from resources randomly (R.drawable.xxxx)

前端 未结 8 940
终归单人心
终归单人心 2021-02-03 14:23

I want to display a random image from the bunch of images i have stored in res/drawable.

The only technique that I know is to access a particular image if you know its r

8条回答
  •  心在旅途
    2021-02-03 14:51

    If you don't mind setting up a XML file, you should be able to use a LevelListDrawable and call setImageLevel() with your random number.

    If you don't want to change this list when you add files, I would assume there is some way of setting up a build event where you could progmatically generate this file.

提交回复
热议问题