I have an activity with a gradient background. Inside this activity there is a linerar layout containing three text views. This layout's background color is black. I want see the activity's gradient background through the textviews. But if I set textview background to transparent then it will be black color, which is linear layout's background color. how can I make textviews to see activity's gradient color?
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).
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 ?
How do I go about implementing a button bar with buttons of different shapes and heights? As an example (please excuse my poor drawing skills for this quick mockup):
The example bar has 3 buttons, with the middle button (3) a different shape and height than the other 2 buttons (1,2). The button bar will be a view that is included and merged into other views so as to seem to float on top of the parent view.
I was thinking of implementing buttons 1 and 2 into a layout, and then button 3 as another layout that I then merge with the first two button's layout.
like my previous comrades said, you need some kind of layout or container that can have a background (if you wish for button #3 to hoover above it) then use relative layout for mixing the two the disadvantage of this other than complexity is that youcannot relate to the other two buttons since they reside in a different layout.
More elegant solution may be to have a special background drawable that can:
have a method setCurrentHeight() that will specify the height the actual viewable section should have the rest will be filled with transparent color.
override it's own draw so just before it's drawing it will have a callback called, call back you can register yourself to.
then you can register the callback in your activity to take the current position of the #3 button and set the height accordingly, this way you are still with one layout with special drawable as background.
A customized LevelDrawable might do the trick.
I would layout this bar as follows:
A RelativeLayout as a container for the rest, with height set to wrap_content and alignparentbottom = true
An ImageView for the bar
2 Buttons with a transparent background (Button 1 and 2)
Button 3 is a custom Button with a custom Image of a trapezoid as background
So you will have a Layout similar to this:
<RelativeLayout
...>
<ImageView
.../>
<Button
... Button 1 />
<Button
... Button 2 />
<Button
... Button 3 />
</RelativeLayout>
I don't exactly know that this will work, and I can't test it, but you might give something like this a try; I believe it can all be done elegantly through XML.
Have a RelativeLayout (id:mainLayout) that will contain all of your views, wrap_content for both dimensions.
Have a blank View as your first child that will serve as your background bar
Set the View's background color/image to what you want; layout_width to fill_parent; layout_height to wrap_content; layout_alignTop="#id/leftButton"; layout_alignBottom="#id/leftButton".
Add an ImageButton for your center button (id:bigButton), wrap_content for both dimensions; layout_centerInParent="true".
Add an ImageButton for your left button (id:leftButton), wrap_content for both dimensions; layout_toLeftOf="#id/bigButton"; layout_centerInParent="true".
Add an ImageButton for your right button (id:rightButton), wrap_content for both dimensions; layout_toRightOf="#id/bigButton"; layout_centerInParent="true".
In my head, I believe this works, but I could be off. Regardless, something to think about, and I hope it helps you find a solution. :)
Better you can tablelayout with different button styles or relative layout for button "3"
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.