2

Fairly new to java (a month into it or so). If you where to look at instagram, they have images stacked on images, with comments, etc.

Looks like a XML layout is just copied and pasted on top of each other.

Is that what they are doing? How can I do that?

Cooper Scott
  • 651
  • 8
  • 18

2 Answers2

3

FrameLayout & RelativeLayout let you stack Views above each other, the z index is by the order they are added in code or written in xml. A layout is basically an extension of ViewGroup with rules, If you want to include another layout in a layout look into <include> and <merge> tags: http://developer.android.com/training/improving-layouts/reusing-layouts.html

Raanan
  • 4,777
  • 27
  • 47
  • Now how could I have for example: Layout 1 Include Layout 1 programatically? – Cooper Scott Jul 29 '15 at 00:23
  • Any Layout can be inflated with View.inflate and check this question about adding the new View to a FrameLayout for example: http://stackoverflow.com/a/8931551/348378 – Raanan Jul 29 '15 at 07:10
1

Here is an example using a FrameLayout and some TextViews. All the views' inside this FrameLayout will appear at the (0,0) coordinate but have an offset found in the dimension of the childs individual view's android:layout_marginLeft/android:layout_marginStart and android:layout_marginTop attributes

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:text="11111111"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dp"
        android:layout_marginTop="6dp"
        android:layout_marginStart="6dp" />


    <TextView
        android:text="2222222"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_marginTop="12dp"
        android:layout_marginStart="12dp" />

    <TextView
        android:text="3333333"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="18dp"
        android:layout_marginStart="18dp" />

</FrameLayout>

And what it looks like:

And what it looks like

petey
  • 16,914
  • 6
  • 65
  • 97