-2

I'd like to create a Layout like this.

Layout example

What is the best way to perform this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Andre
  • 1,149
  • 2
  • 10
  • 18

3 Answers3

1

There are several ways to do it, first and common step is define border around parent layout and define margin for child layouts. after that in second step you can use one of the following to achieve this.

  1. you can use Linearayouts with orientation vertical and then by using weightsum and weights you can achieve this.

  2. another approach is by using Relative. in relative layout you can provide other views position relating to other layout component position.

  3. third approach is by using Constraint layouts, provide constraints and you will achieve this.

Jay Dangar
  • 3,271
  • 1
  • 16
  • 35
1

You can use this code to make that design:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:orientation="vertical">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@android:color/black"
        android:layout_weight="0.4"/>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.6"></RelativeLayout>

</LinearLayout>

You can change values of layout_weight to change the rate.

Onur
  • 25
  • 1
  • 8
0

Some of the ways to achieve this layout and a few a performance cautions with these are stated below:-

1.With a linear layouts using the weights parameters will cause a performance hit, as the it would cause the views to be measured twice before being layout.And we has a deeper heirarchy with linear layouts which again causes slow rendering.

  1. With relative layouts , even though we get a flat heirarachy but the views are measured twice before drawn, again a nested relative layout (relative layout with in another relative layout) will cause the rendering time to increase as now, the view would be measured 4 times.

3.It would be better to use constraint layout to get the better performance with flater view heirarachy.

4.You might also want to consider using fragments if the inner layout has a menu structure causing changes in first child , with frame layout as the root parent.

A few links to understand about the performance benefits:-

Android Layout Tricks #1

Understanding the performance benefits of ConstraintLayout

Kaveri
  • 1,060
  • 2
  • 12
  • 21