Partially hide Layout programmatically? - android

What should I do to partially hide some layout from code? Should I play with setMargins?
Basically, I want to detect size of the screen and then I want that element X becomes visible only 10% of its width? I know how to do it all except how to make it partially hidden or offscreen?
Look at these images to see what I want to achieve. Image 1 - UI element is in the center. Image 2 - I set in code it's moved to top offscreen thus becoming only partially visible.

I found out that here as well the best solution is to use Animation (TranslateAnimation) by setting this on the first screen load and setting its speed to minimum value of 1 millisecond. The transition in reality is unnoticeable to a human eye.
Also do not use margins as they simply "push" element from one side without making it goes offset. If you have any child in the layout you want to offset, they all will be squeezed as you increase margin values.
NOTE: if you ever want to use animation on that screen on the element you offset before, take into account the negative value of offset. Otherwise your animation will not look nice. To avoid bumping effect, take special care of fromXDelta value.

Related

Android drag and drop, endless layout

I want a screen to arrange rectangles with drag & drop. Elements can be moved freely, so it's not a grid or list. I think I should use absolute positions.
My main problem is that I need an endless screen (when drag to right, scroll the screen to the right). One solution I found was to set width and height to 10000dp and a 2d scroll. Another way is to resize the container each time the user drags an element.
I need a better solution if possible. Any suggestions?
Resize the container each time the user drags an element out of the current view bounds should be the most performant idea.
By the way you should put some max size limit to the view, otherwise you will run out of RAM fast and your app will crash.

Controlling the positions of a views in Android

I am trying to create an android app where I have a single relatively big button in the middle (the light blue in the picture) and it is surrounded by other smaller buttons as shown in the picture (some of small buttons might be visible or invisible based on some criteria).
I started with the RelativLayout setting the big on in the center and making the rest placed in relation to it, but it is a miss and the central button get shifted and doesn't stay in the center. I tried placing them in FrameLayout and used margin to adjust their locations, that worked the best however, the spacing changes on different screen resolutions.
So what is the best way to achieve such layout that will look consistent on any device?
Android's Percent Support Library allows you to use proportions to lay out your views, which may allow you to get closer to your goal.
http://developer.android.com/tools/support-library/features.html#percent

Android clip upper part of text in TextView

I need to have two TextViews displaying same number, first of which should display upper half and second lower half in order to animate those parts differently. (See images below, there's an example with '8' digit).
http://img403.imageshack.us/img403/2461/bottomtop.png
While clipping bottom is perfectly simple (setting TextView's height is just enough), the second task I find very hard. The only solution I came up with till now is to wrap TextView into some layout and set it's y position to negative - it would be OK, but I need to care about optimization because there will be many digits animated in that way simultaneously.
Do any of you know how to achieve this in more effective way?
What about overlaying the top textview OVER the bottom textview (maybe with the white spacer as well?

Android ScrollView: Automatically scroll to a few pixels (dips) above a certain view

I am aware that I should decide how many pixels based on density.. not hard coded.
I have section headers and items displayed in a scrollview and I want to scroll to a certain section header (the one for the current date) while making it clear that it is not the top of the screen (show about half of the previous item).
How can I do that? I do not want this automatic scroll to be animated.
With View.requestRectangleOnScreen() you can scroll to show a particular rectangle (the linked method allows disabling animation). You still will have to calculate that rectangle, but once you have the position of the particular child (your header) you can easily do that getting the size of the ScrollView. You could consider the small offset you want in calculating that rectangle or just do a scrollBy() after requestRec....() (the former way is better I think).
An easy way to use a density independent dimension is to define it in xml as a dimension resource.
-- edit: you get the position of the child in parent with getLeft() / getTop().

Android: How do you scale multiple views together?

I'm trying to layer graphics one top of each other, like an icon over a background, with the second layer (icon) at a certain pixel offset from the top left corner of first layer (background). Since each layer will eventually have its own animation, I'm placing each in its own View.
For my implementation I have two ImageViews, one for each layer, inside a RelativeLayout, which in turn is inside a ScrollView. ImageViews are positioned using layout_margin relative to the top left corner (0,0). The first ImageView is larger than the screen (background), while the second ImageView is smaller than it (icon). ScrollView automatically resizes the first ImageView (background) since it is larger than the screen, it does not resize the second since it is smaller (icon).
I need both of them to scale together, and I also need the positioning of the second layer over the first layer to adjust itself accordingly. This actually works well in a layer-list, but due to the animations I am forced to use Views. How can I scale and position multiple Views together, or do I need to build my own class for something that seems like it should be fairly basic?
Thanks in advance.
I had a similar problem in my android application. Android has introduced new set of API's to help us on this, setScaleX() and setScaleY().
Just call layout.getParent().setScaleX(); and layout.getParent().setScaleY();

Categories

Resources