1

How do I achieve the following vertical layout in Android ?

View1
View2
View3

All three views have width that fits the screen.

View2 height is fixed (= 100).
View1 height is equal to view3's height.

Am I able to achieve this with LinearLayout, RelativeLayout, ConstraintLayout?

I'd appreciate if there is a programmatical solution, instead of the XML layout.

Goku
  • 9,102
  • 8
  • 50
  • 81
user1615898
  • 1,185
  • 1
  • 10
  • 20
  • `Am I able to achieve this with LinearLayout, RelativeLayout, ConstraintLayout?`. Yes, by using all those ones you can, And also by using TabLayout or GridLayout you can achieve the same result. – Phantômaxx Nov 28 '17 at 08:28

2 Answers2

5

Try this using LinearLayout

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


    <View
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/colorDarkBlue"/>

    <View
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"/>

</LinearLayout>

OUTPUT

enter image description here

Goku
  • 9,102
  • 8
  • 50
  • 81
0

Not sure this is what you want but you can get screen height.

Subtract View2's height and just set heights of View1 and View3 to half of your result.

You need to use RelativeLayout and sort them as you want.

Goku
  • 9,102
  • 8
  • 50
  • 81
dcanbatman
  • 165
  • 1
  • 13