I have a rectangular LinearLayout that has some margin, some round corners and an alpha value of 0.3. Inside this layout I have 4 different layouts as I display different im
You can solve your problem with this solution. It works perfect.
parentView.getBackground().setAlpha(128); //your parent view's visibility is now %50 and child view's visibility remains same.
I actually figured it out! The colors are AARRGGBB, so modifying the alpha channel (AA) only affects the current background and not the children! If there is another solution, I am happy to hear it. Thanks!
To prevent a child view from being affected by it's parent background ...
Truth: A non-alpha-255 'color' is not actually a color - it is merely a tint!
Thus: the perceived appearance of a child view background is either:
(a) The exact color specified by child.setBackgroundColor() when that color has alpha-255 or:
(b) A composite of child.setBackgroundColor() and the parent background otherwise.
To absolutely control the child background (with utter disregard the parent) you must therefore construct a third color which will be a composite of your chosen tint and your chosen alpha-255 background.
You must nominate a background! (By definition, a tint can only be rendered against a background. If not explicitly specified the theme background will eventually come into play.)
This code took months to find and is giving perfect results.
childView.setBackgroundColor(ColorUtils.compositeColors(yourTint, yourBackground);
See my answer to my own question here.
This may be late answer
But Try this below code i hope u get what u need
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/aa" //Your own Image in root element
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/RLMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CCFFFFFF" > //Your Alpha Value
<ImageView
android:id="@+id/iv1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp"
android:src="#FF0000" /> //Your Child Image
</RelativeLayout>
If you want to set the alpha only to the parent parent layout and don't want it to be translated to its child views. Use Hexadecimal color with transparency code added to it.
Ex- Let say the background color for your Linearlayout is #FF0022 and you want to set it's opacity to 82% then add D1 to your hex code and use #D1FF0022 hex code for your viewgroup background where D1 is the parameter for the opacity of 82%
complete list of transparency code can be found here