I have followed the article Layout Tricks: Using ViewStubs to set a View on top of another. I used FrameLayout as the root element containing one MapView and a ViewStub. At the place for ViewStub I later opened a LinearLayout with the android:background set to a color with color value <color name="blue_opaque">#f005</color>.
The position for the LinearLayout seem to be right, it sits on top and it has a blue background but it is not transparent. What am I doing wrong?
The color hex code is built like this. #ARGB or for a more fine grained control #AARRGGBB which means AlphaRedGreenBlue. You set your alpha to 100% be opaque. Try #6005.
Related
I have a relative layout with child TextViews.
The background of the parent RelativeLayout is white and I was wondering how I could change the alpha to change the opacity of the whole view programmatically (including children).
I am trying:
getBackground().setAlpha(0.4);
But that expects an int and not a float.
If I do:
getBackground().setAlpha((int)(0.4 * 255));
The latter changes the view but makes it darker than I want. Also the children do not seem to change. It seems to affect only the background while I want something that makes everything more "grayed" out/less transparent.
What am I doing wrong?
Have you tried using android:background="#88000000" in layout file. You can change alpha and color values as required.
That's because you are changing the backgound of the layout and not the layout itself. So instead of myRelativeLayout.getBackground().setAlpha(), use this: myRelativeLayout.setAlpha(0.4f).
What I want to achieve is something like this, a seekbar without any top and bottom padding:
What I get is this:
I tried even setting the background to transparent and then null but the background of the seekbar becomes white, it doesn't look like in the first image, I want the seekbar to look like it's placed between the both layouts (the upper layout is darker, and the layout from the bottom is lighter as you see in both photos). I'm using the basic attributes for the seekbar in xml, thanks!
EDIT:
This is the seekBar in XML.
I don't believe that it has something to do with the root layout, because everywhere if I'm starting a new project and I'm adding a seekbar it still has that background, and if I try to set it to transparent it becomes white.
<SeekBar
android:id="#+id/window_song_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:paddingLeft="0px"
android:paddingRight="0px" />
Set following attributes in xml.
'android:paddingStart="0dp"
android:paddingEnd="0dp"'
SOLVED, bad layout positioning. I was using a LinearLayout as the root element with a vertical orientation, the seekbar was at the middle of two relative layouts, I used android:background="#color/myColor" for the root layout, then setting the background to transparent to the seekbar and now I got the desired effect. And also I changed the root layout from linear layout to a relative layout. Thank you! :)
I was wondering which views have background #null by default and on which views it's recommended to add it in order to reduce the number of overlays? For example in the following construct:
relativelayout
relativelayout
framelayout
view
If I want a white background (where only one view in the xml has this background - no overlaying of white on white), and I only define 'background white' for the highest relativelayout - will all the other layouts have a background "layer" or not (if none is specified)?
I have a LinearLayout called mySlab inside another RelativeLayout. I need to make the mySlab and its children views transparent programmatically. Do I have to make each child transparent explicitly or is there a way such that if I turn mySlab transparent the children will follow?
A bit of clarification
The layout view in question has a number of children each with its own color or image background. I am hoping to be able to dial the transparency of mySlab without actually changing the colors and backgrounds of each child per se. iOS does that very well.
Also mySlab is actually a RelativeLayout, not Linear, though I don't think that should matter.
its easy in android, use this property
android:background="#00FFFFFF";
where 00 is for tansparency, and rest for rgb color.
Have you tried this:
LinearLayout ll = (LinearLayout)findViewById(R.id.myLayout);
for (int x=0;x<ll.getChildCount();x++)
ll.getChildAt(x).setBackgroundColor(Color.TRANSPARENT);
ll.setBackgroundColor(Color.TRANSPARENT);
this will change the LinearLayout and its childrens
I am developing an app with an activity with member reactions on a hike event. The reactions are the yellow "balloons" which are made using a LinearLayout. Each item is constructed from a XML file (listitem_deelnemerreactie.xml) which defines the layout for a reaction item. The top level of this layout file is a LinearLayout my itself.
I want some spacing between the separate elements, as well as some right margin. The most straightforward way to so this should be: setting a bottom and right margin on the top-level LinearLAyout element of the listitem_deelnemerreactie.xml layout file.
But setting the bottom margin on the LinearLayout has no effect on the vertical spacing, though the right margin does have an effect.
The only way to be able to set a vertical margin appears to be: setting is in the Java code, after attaching the inflated view to the container.
See the two images for the effect and the code.
Though setting the margins in the code is a working workaround, I still think it is strange this cannot be achieved in the XML. Why is the bottom margin attribute ignored while the right margin is not?
Any ideas?
Have you tried to set an android:padding="10dp" for example on your elements to spaced them ?