2

LHS of the following disagram shows the initial structure of the Activity set up in XML, and the RHS shows the Activity after some runtime changes.

The black border encloses the RelativeLayout (I can change it to LinearLayout or something else if that solves my problem) which is the root of the Activity's layout, the red border encloses a RecyclerView, the green border inside it encloses an element of the RecyclerView. The dark blue border encloses a FrameLayout to which a Fragment will be added at runtime.

Now the thing is that at runtime, some more elements are added to the red bordered RecyclerView, collectively shown by purple-bordered box in the RHS of the diagram. Only the part of the RecyclerView containing these newly added elements should overlay the rest of the Activity's content (i.e. essentially the FrameLayout)

So what kind of layout should I use as the root of the Activity, how should I make this part-of-a-layout-overlapping-the-neighbours thingy possible? How should I go about it? Any suggestions will be greatly appreciated.

enter image description here

Solace
  • 8,612
  • 22
  • 95
  • 183
  • 2
    So your question is to how to achieve the xml to do what is described in the images above? If that's the case, you'll need to guarantee that the height of the green box is always the same - in which case you can set the blue box's `layout_height=match_parent` but add `layout_marginTop=[static_height_of_green_box]`. Also make sure the red box is marked up below the blue box. – em_ Sep 09 '15 at 14:39
  • @ElliotM Firstly, thank you indeed! _"If that's the case, you'll need to guarantee that the height of the green box is always the same"_ it is always the same, but is `wrap_content`, while the content is Not dynamic. So the height of the green box does always remain the same, and what it contains is a horizontal `LinearLayout` containing an `ImageView`, an `EditText`, and an `ImageView`. – Solace Sep 09 '15 at 15:19

1 Answers1

2

With RelativeLayout, FrameLayout and CoordinatorLayout you can achieve overlap layout.

However it may need more details to know which is best for you.

Edit:

If the green layout is having fixed height, say, 100dp, seems you could easily get what you want with RelativeLayout

<RelativeLayout>
    <FrameLayout android:height="match_parent"
        android:width="match_parent"
        android:layout_marginTop="100dp"/>
    <RecyclerView/>
</RelativeLayout>
Derek Fung
  • 8,171
  • 1
  • 25
  • 28
  • 2
    Hey nice edit! Two things: it's `layout_marginTop` and I believe you have to move the `RecyclerView` xml below the `FrameLayout` xml otherwise the `FrameLayout` will get rendered on top – em_ Sep 09 '15 at 14:47
  • @ElliotM _" you have to move the RecyclerView xml below the FrameLayout xml otherwise the FrameLayout will get rendered on top"_ but why will the `FrameLayout` get rendered at the top, when it occurs after the `RecyclerView` in the view hierarchy (i.e. its XML element is written after the XML element of the `RecyclerView`) within the parent `RelativeLayout`? – Solace Sep 09 '15 at 15:11
  • Firstly, thank you very much for the answer. I like the solution, it had also occured to me, but unfortunately the `layout_height` of the `RecyclerView` is `wrap_content` so I can't probably go that way =( – Solace Sep 09 '15 at 15:15
  • 1
    @Solace, the later the view in the layout, the later it is rendered, so the later will be on the top. – Derek Fung Sep 09 '15 at 15:19
  • @DerekFung Ooh OK OK I get it. Thanks – Solace Sep 09 '15 at 15:20
  • 1
    @Solace, actually what you want to display on the RecyclerView? It sounds strange to me to have RecyclerView with wrap_content, it sounds more like a LinearLayout to me – Derek Fung Sep 09 '15 at 15:21
  • 1
    @DerekFung No no no, it's not a RecyclerView with the `wrap_content` height, it is a row of the RecyclerView (a `ViewHolder`) having that height. Initially, it is just this one row, later other rows will be added. – Solace Sep 09 '15 at 15:44
  • 1
    ic, maybe you have to consider to set the marginTop programmatically with global layout listener – Derek Fung Sep 09 '15 at 15:47
  • @DerekFung Actually I tried set a `android:marginTop="35dp"` (just shooting in the air) on the `RecyclerView`, which gave me an idea that I need to increase it a bit, then I tried `50dp` and it is the perfect `marginTop` I needed. I think that's called bootstrapping. =P I am marking your answer as accepted. – Solace Sep 09 '15 at 15:53
  • 1
    Glad that this helped you more or less :) – Derek Fung Sep 09 '15 at 16:15