How to make a linearLayout partially transparent in android?

前端 未结 7 1747
刺人心
刺人心 2021-01-31 04:01

I have a RelativeLayout containing 2 LinearLayouts one of them is partially covering the other. I want to make the part of the LinearLayout

7条回答
  •  情歌与酒
    2021-01-31 04:39

    When we set the color it is like ARGB(Alpha Red Green Blue). You need to change the alpha in the color code to increase or decrease the amount of Transparency :

    You can range it from 00 to FF (Hexa Decimal)

    For maximum transparency => #00555555 (Here 00 stands for the alpha)

    For minimum or no transparency => #FF555555 (Here FF stands for the alpha)

    So, for setting the transparency of an ImageView you can code like this:

    ImageView image = (ImageView) findViewById(R.id.myImage);
    image.setAlpha(0.3);
    

    Also, you can set the alpha for your LinearLayout like this :

    LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout);
    ll.setAlpha(0.4);
    

提交回复
热议问题