stretch and shrink a row instead of a column - android

I'm looking to lay out a view similar to how TableLayout works, which can automatically shrink and stretch columns, except I want a row to be stretched and shrunk.
Basically I want to have a fixed-height button (dp) button at the top of the screen, a fixed-height button (dp) at the bottom of the screen, and an ImageView in the middle. I want the ImageView to be stretched or shrunk as needed to accomodate the two fixed-height buttons.
Using a TableLayout with orientation=vertical doesn't seem to do the trick.
Any ideas?

you can use relative layout to do waht you need. Attach the two buttons to the top and buttom respectively. Then for the image you can align its top to the buttom of top button and its buttom to top of buttom button.

Related

Divide screen to two halves with a title for each and center a view inside each one that will shrink or expand to fill the space

I'm trying to create this kind of layout in android.
I'm using constraint layout. I want to divide the screen with height y to two halves with y/2 height each.
Each one of them will have a textview as title which takes the whole width and has constant height.
And a circular custom view which I would like to expand or shrink so it fills the whole half so the padding marked as 'auto' will all be the same but dynamic.
And p will be a minimum padding that the view can't be over them.
The aspect ratio should of those circles should not be changed.
Is that even possible doing it in the xml design editor? or do I have to do it programmatically.
Next step will be to arrange those halves to be side by side if it's a landscape view.
OK, I did it, Basically you drag the 4 edges of a each view to center it in the outside element. And set the margins to .
So I dragged title2 to all directions of the screen and it got centered. Then I dragged each of the circular views edges the same way so the upper view I dragged to title1 and the bottom to title2. The bottom view I dragged its top to title 2 and the bottom to the bottom of the screen.
Auto resizing is done by setting layout_width to 0 and layout_height 0.

Animate TextSwitcher, ViewFlipper or ViewSwitcher with children of different heights

I want to use a TextSwitcher (or some other switcher with TextViews inside) to animate changing Text.
It should have a sliding animation to slide the old text out to the left and the new one in from the right.
My problem is that when a long text gets replaced by a short text, the TextSwitcher changes its height to a smaller view and the view that is moving out of the screen changes its height too. I want the animated view that is moving out of the screen to keep its height until its gone. Only the new Text should have the new height.
I have
android:measureAllChildren="false"
enabled because my TextView is centered vertically.
I have tried using TextSwitcher, ViewSwitcher and ViewFlipper, but all of these changed the height of the text that was sliding out.

ConstraintLayout alignment with offset

I am using a ConstraintLayout with two views inside. An ImageView that varies in size depending on the image loaded and a View which acts as a custom made dropshadow for the Image. What I've been doing so far is adding 8dp padding to the ImageView and then aligning all of the edges of the View to the ImageViews, thereby making the View stick out 8dp underneath the ImageView.
Now for several reasons I don't want to keep the padding on the ImageView but I still want to achieve the same effect. So basically I would like to align the Left of the View to 8dp left of the Left of the ImageView (and the same for every other edge, right, top, bottom).
Is there any way to achieve this?
Thanks in advance!
I´ve been having problems with this too, it seems ConstraintLayout does not support negative margins yet: https://code.google.com/p/android/issues/detail?id=235306.
In my case, I want a 20dp negative margin to a set of overlapping images on a header image. So far, I'm positioning an empty TextView below the guideline my header image is connected to, with a 20dp top margin and aligning my overlapping image views to that.

Android: how define android:layout_span for height

Suppose there are two Button in TableLayout and if I mention android:layout_span="1" in both the button then the complete width is divided into two part and each button sit into one part.
Can we achieve this same thing for height.
In my application four button is there which arranged in linear order one on the top of other.
I want all these four button cover complete height of the screen in any size of screen.
My Problem is here if I launch this screen on one device then it look like:-
But if I launch this layout on big screen then it looks like:-
How on all the screen the button cover(uniformly distribute)?
Set the layout height for each view to be 0 and instead use layout weight. Use the value 1 for layout weight for all the buttons for them to be equally spaced!

relativelayout space between its elements when background image is present

I have a relative layout with background image (9patch). I have set this image as background to the layout using xml. When I add another relative layout which has buttons and textviews, there is little space left before the new layout. I didnt set any padding. I also tried by setting padding top to 0. If i remove the background image the alignment will be proper with no space left on top of new layout. I have also tried by setting match parent and fill parent in new layout but still the space remains on top of it. The space left is very little like 3dp-5dp.
can someone suggest about this issue pls.
EDIT : space is on top of the new layout horizontally and i have tried setting gravity to top and also top left.
The black pixels on the top and left define the stretch area of the 9-patch, while the pixels on the bottom and right define the fill area. My guess is that you have a fill area defined that does not cover the entire right and bottom edges.
Here's a good guide.

Categories

Resources