Android and setting alpha for (image) view alpha

后端 未结 9 1387
终归单人心
终归单人心 2020-11-29 00:20

Is there really no XML attribute counterpart to setAlpha(int)?

If not, what alternatives are there?

9条回答
  •  温柔的废话
    2020-11-29 00:47

    I am not sure about the XML but you can do it by code in the following way.

    ImageView myImageView = new ImageView(this);
    myImageView.setAlpha(xxx);
    

    In pre-API 11:

    • range is from 0 to 255 (inclusive), 0 being transparent and 255 being opaque.

    In API 11+:

    • range is from 0f to 1f (inclusive), 0f being transparent and 1f being opaque.

提交回复
热议问题