I would like to create a layout as in the image. It did not include him, so the code is very long. I want to create a layout for each BOX and include it in the main layout, one below the other.
The problem is that the XML file a layout of this type is very long. So I would use includes layout and create a new layout which then repeatedly will include, for example:
I have a RelativeLayout, and I have an ImageView for the line1, below I want to design the box in this method to reduce the code:
<include layout = "box1"
layoutBelow = "linea1"
/>
And the same for the box 2:
<include layout = "box2"
layoutBelow = "linea2"
/>
But the layout I include not aligned as I would like. The layout is superimposed on the existing one.
To efficiently reuse complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
Android Studio informs me that for these types of includes to work that layout_width
and layout_height
must also be specified in the include tag, otherwise layout_below
is ignored.
I have solved in this way:
<!-- LINE SEPARATOR 1-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/logo"
android:id="@+id/linea1"
android:background="@drawable/linea"
/>
<!-- BOX1 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linea1"
>
<include
layout="@layout/box1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</RelativeLayout>
<!-- LINE SEPARATOR 2-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/logo"
android:id="@+id/linea2"
android:background="@drawable/linea"
/>
<!-- BOX2 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linea2"
>
<include
layout="@layout/box2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
</RelativeLayout>
And the result is this image:
Thanks you all :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With