How can I make an image transparent on Android?

后端 未结 12 1687
春和景丽
春和景丽 2021-01-30 19:52

I am using a linear layout and frame layout. In the linear layout I keep an image as background and in the frame layout I keep an imageView. In that imageView I give an image.

12条回答
  •  渐次进展
    2021-01-30 20:19

    Try this:

    ImageView myImage = (ImageView) findViewById(R.id.myImage);
    myImage.setAlpha(127); //value: [0-255]. Where 0 is fully transparent and 255 is fully opaque.
    

    Note: setAlpha(int) is deprecated in favor of setAlpha(float) where 0 is fully transparent and 1 is fully opaque. Use it like: myImage.setAlpha(0.5f)

提交回复
热议问题