Android: Keeping Image Visible Throughout Animation - android

Background:
I have an Activity that comprises four buttons that each take up a quarter of the screen.
It contains a horizontal LinearLayout that is divided in half by two vertical LinearLayouts as shown in the image below:
http://i.stack.imgur.com/P7Wd3.jpg
Desired Effect:
When I touch a button, I would like it to animate and fill up the entire screen.
Issue:
I have accomplished the animation aspect by changing X and Y scales from 1 to 2 onClick.
The problem is, however, that the animated button will not show when it leaves its parent LinearLayout.
Thoughts
I have tried making the non-animated buttons invisible, but the animated button will only show in its parent LinearLayout.
I know this problem would be solved if I had used a single LinearLayout, but I was unable to use the "layout:weight" feature to make each button take up half of both width and length.
So... How should I approach this issue?
I would appreciate any help :)

Try using a single RelativeLayout. Check this post for a nice example. You may have to setVisibility(View.INVISIBLE) for the other buttons.
Alternative:
Construct a RelativeLayout as above but put that as the only child
of a FrameLayout.
When animating a button, remove it from the RelativeLayout and add it to the FrameLayout specifying the gravity in the LayoutParams appropriately. This way the rest of the buttons will also be seen in the background during the animation.

Related

Android animateLayoutChanges does not work properly for ScrollView with fillViewport true

I am trying to animate layout changes for a LinearLayout contained in a HorizontalScrollView with fillViewport=true. The idea is that I have a dynamic bar of buttons that should distribute to fill the available space, but if there are too many buttons you can start to scroll left/right to see them all.
This all works great, and using animateLayoutChanges=true on the LinearLayout works smoothly if the HorizontalScrollView has fillViewport=false, but as soon as it is set to true, jerky motions start to happen:
You will notice that the settings button jumps straight to its new position, while the right two buttons initially jump, but then animate a little to their final positions.
For me it seems relatively clear that the problem is that the extra x-offsets introduced by fillViewport=true are applied instantaneously, while the remaining shifting of the buttons is animated as normal.
Is there any way to get the animation to consider the effects of fillViewport=true as well?
Details only in case it matters: My HorizontalScrollView contains a LinearLayout that for each button contains a FrameLayout containing a Button (required in order not to stretch the button clickable area). I have tried applying animateLayoutChanges to the scroll view, to the frames, to the buttons, etc as well, but no combination seemed to make a difference.

What is the best practise for padding or margin in Android?

I am relatively new to Android UI. I always get confuse in providing margin to different view like should i provide bottom margin or should i use top margin(to view below it). Also should i use RelativeLayout or LinearLayout if both can solve my problem.
Thanks
It Depends on your need
Linear Vs Relative
If you just want to stack your TextView and Button horizontally or vertically you should go with LinearLayout.
If you want to make a layout that is more complex for example you can have an ImageView covering all of the screen and Button over the ImageView or if you want your layout elements to be stack on corners or at bottom, RelativeLayout is your Guy.
Top margin vs Bottom Margin
It doesn't make much a difference its a personal preference, I Use margin-bottom on first element rather than margin-top for second element.
One noticeable difference is when you are working with Show layout bounds during development. You can see here those pink coloration indicate that it is using margin on its view while padding has no coloration. Recently I prefer to use padding if applicable with my requirements as it seems more cleaner to inspect UI when Show layout bounds is enabled from Developer option.
The image is not mine and was just use as a quick sample.
If both Linear and RelativeLayout will solve your layout, then you should use Linear as it is faster to render.
With regards to top vs. bottom Margin. That's entirely your preference and how you want to think about the elements. Does Item A always sit 40dp above the next item or does Item B always sit 40dp below the previous item?

RelativeLayout android:clipChildren="false" does not work: Animation will get clipped?

I am trying to implement a scrolling "newsbar". There is a RelativeLayout which fills the screen horizontally. It should contain many different news titles, contained by TextView objects, which I download from the internet and they should be animated in order to slowly moving from right to left, which will generate a "scrolling newsbar" effect. I place the first TextView as RelativeLayout.ALIGN_PARENT_LEFT and all the consecutive TextViews aligned as RelativeLayout.RIGHT_OF according to the previous TextView. So, the text would enter from the right side of the screen and flow through the layout and finally exit from the left side.
I see that the RelativeLayout clips children which are outside of its bounds. I set android:clipChildren="false" for this purpose but it does not function and the TextViews continue to get clipped, which is very annoying and is currently blocking my progress.
Is this a bug or am I doing something wrong?
Please help me...

Slide application

We have layout which contains imageView, textView1, textView2.
The goal is to make available sliding like in photogallery. But where to set OnTouchListener?
On layout? It is covered b other views. On every view? it seems also not a good solution.
I was told that I have to add one more layout that will fill_parent (on the level, where textViews and imageView). It will be invisible. I did it, but it also does not work good.
Thanks.

Linear Layout Issue at Runtime

I am trying to build a layout dynamically which display some text and image for the most part, but has a series of buttons placed next to each other in the bottom.
I have a linear layout that carries the text, another linear layout that carries the image. And yet another linear layout that carries the buttons that get created in a for loop. I have a main layout aligned vertical that adds the text, image and buttons layout, in that order. To finally generate something like this:
Text ....
Image ...
Button1 Button2 Button3....
The problem is the number of buttons get decided at runtime, so if there are more than 4 buttons, the 5th button gets displayed really tiny. Also, when I tilt the phone, I get only the text and image showing, but no buttons coz the image covers the entire screen.
Layoutting seems to be pretty complicated to me, any help is appreciated!
Thanks
George
You do not need to wrap single views in a linear layout, so add the text and image directly to the root linear layout. You might consider using a relative layout instead of linear for the root.
Using FILL_PARENT and WRAP_CONTENT for the LayoutParams width or height can give some useful results. For example, using FILL_PARENT for the image height might scale it down to leave room for the buttons.
Be careful with LayoutParams because there are lots of them and only the one that matches the ViewGroup class should be used.
One option would be to implement an onLayout method of your own in a custom ViewGroup. You will be passed the dimensions you have to work with and be able to position all the views as you see fit.

Categories

Resources