In my layout file I have a ConstraintLayout as the parent and 2 child views.
Player View (displayed with ratio of 16:9)
Controls View
I need to layout the player controls on top of the player view (cover it) and add 10dp of height so it goes even a little higher than the player view.
Is there a way to achieve this with ConstraintLayout without adding more ViewGroups to the picture?
Here is one way to do it:
Place a Space view on top of the player. Make the height of the Space view 10dp.
Constrain the control's top to the top of the Space view and its bottom to the bottom of the player.
The Space view will not show but will help to provide the positioning you want.
Related
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.
The pattern of the layout is below:
---LinearLayout vertical
---LinearLayout -> contains a LinearLayout that shapes like rectangle(setVisibility-> Gone)
---RecyclerView -> below the above layout of rectangle
Originally, I set a slide-down animation of RecyclerView from the top of the window to a position where it gives enough space for the rectangle to show and when the animation ends the LinearLayout of rectangle is shown by invoking the method setVisibility(Visible)
Problem: when I set the rectangle visible, it is visible as expected but recycler view is dropped down the space as much as the rectangle's height, leaving blank space between the rectangle and the RecyclerView. I wonder what might cause this and how to fix this? Thanks!
I think you may not change the position of the RecyclerView and only set the visibility of the LinearLayout to visible. Changing the visibility will redraw the whole layout and the layout that was Gone will take its needed height, so the space between the top of the recycler view and the bottom of the layout will be (animation height + layout height) and that is why there is an empty space
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.
I'm trying to do a TweenAnimation (Scale and translate) with two ImageViews (top and bottom). Each ImageView (and some other stuff) is in a RelativeLayout and the RelativeLayouts are in a LinearLayout. The images moves to the left top corner of the display. The Animation works fine, but at the end of the (Relative) Layout the animation disappears (in the mid of the display).
Is there any way to give the animation more (all) space then only the parent View? Thanks!
You can set the parent view to not clip it's children and allow them to draw outside it's bounds. In your XML, add this:
android:clipChildren="false"
How could I proceed to place an item on a LinearLayout, with a given space from the top? For instance, I would like to place the logo on the half of the top middle of the layout.
Thanks
There is no way to add percentages.
You can add two layouts with the same weight to split the screen in two and then add the logo with a centered gravity to the upper layout,
Or you can measure the screen and add the right amount of margins.
Use the paddingTop attribute of the view class.