Animate view regardless of its layout-container - android

I'm trying to apply a TranslateAnimation to an ImageView inside of a LinearLayout. As soon as the ImageView(marked "1" in the image below) crosses the bounds of the LinearLayout that contains the ImageView, it goes "black"/disappears. This does NOT happen if I animate the entire green LinearLayout, so I don't think it has to do with it's z-value. Rather, I believe that the ImageView can't visually "escape" its container layout (green). What can I do to make the ImageView display in front of everything when the animation is being performed? I've already tried .bringToFront()(followed by .requestLayout/.invalidate of the root view).

Try to set android:clipChildren="false" in a parent container

Related

Centering a Linear Layout Horizontal and Vertical

Im running into a speed bump in my android App. I want to center my Linear Layout in the center of the screen (Horisontally only) and I want to center another element only vertically. I haven't seen an easy apparent way to do this in the program.
http://i.stack.imgur.com/gfMBD.png
I want the grey Box to be centered horisontally in the app
I'm not sure, how your layouts are now, but I'd do something like this:
Vertical Linearlayout
RelativeLayout, centered horizontally
RelativeLayout, set to match parent
RelativeLayout, centered vertically
Use RelativeLayout as a root ViewGroup, and then just add android:layout_centerHorizontal="true" to your first LinearLayout, and android:layout_centerVertical="true" to your second one.

Bottom margin Android LinearLayout item in XML ignored, but works in Java code

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 ?

Android, Specify what View should be shrinked if no space

I've got next problem.
There is ImageView and button panel below it. I want ImageView to be as large as it needs, but if there is no enough space button panel should be present on screen and Imageview should be shrinked. What is the best solution for that?
Have a look to the android:layout_weight attribute.
What does android:layout_weight mean?
In case there is only 2 views in one layout (ie. Imageview and button) you can put both view in linearlayout and give value 1 for imageview weight layout (and doesn't give any value for the button)

I have created Progressbar programmatically, now how can i keep it center of screen and ontop of other views when made visible inside linearlayout?

I have created Progressbar programmatically, now how can i keep it at the center of screen and ontop of other views when made visible inside linearlayout ?
Consider using a RelativeLayout instead of the LinearLayout and add attributes to your ProgressBar: centerInParent = true.
Covering up views under another view can only be done in RelativeLayout (or FrameLayout, but more tricky)

How do I overlay the window with an image on top of all the views?

I am trying to place an overlay on top of my Activity. In other words, I would like to put a gradient on top of the whole screen with all views behind it.
I currently have a LinearLayout with my buttons and everything in it. Do I extend the LinearLayout and add something on the onDraw method, or is there any way I can add another layout that overlays everything?
You can do two things:
replace the LinearLayout with a RelativeLayout and so you can easily place anything you want on top of each other
wrap your LinearLayout in a FrameLayout. The FrameLayout draws everything in order of definition/adding so your gradient should be the last added view/layout.
Something like that:
<FrameLayout>
<LinearLayout>
<Your stuff>
</LinearLayout>
<GradientView/>
</FrameLayout>

Categories

Resources