-4

All,

I know this is not difficult one, But I just want to know that which is the best way to achieve This. You can see two icons exactly between two layouts (blackish and white). I know we can achieve this using margin but is there any other better way ?

P.S To clarify the confusion this is what my entire screen should look like actual screen

Thanks in advance. Answer will be appreciated.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Kalpesh Lakhani
  • 1,003
  • 14
  • 28

3 Answers3

2

Try This

Output:

enter image description here

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.nct.dhruv.demotest.LogCatActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/colorAccent" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_centerVertical="true"
        android:layout_alignParentStart="true">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_marginRight="10dp"
            android:orientation="vertical"
            android:layout_height="wrap_content">

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/floatingActionButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"
                app:backgroundTint="#fff" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_height="wrap_content">

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                app:backgroundTint="#fff"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher" />

        </LinearLayout>

    </LinearLayout>


</RelativeLayout>
ND1010_
  • 3,743
  • 24
  • 41
2

You can Achieve that Design using RelativeLayout enter image description here

Try this

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


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/nilu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccentJob"
            android:orientation="vertical"
            android:paddingBottom="30dp">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />


        </LinearLayout>

        <LinearLayout
            android:id="@+id/nilu2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/nilu"
            android:background="@color/colorAccentAdhoc"
            android:orientation="vertical"
            android:paddingTop="30dp">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/nilu"
            android:layout_marginTop="-15dp"
            android:orientation="horizontal">

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginEnd="16dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_toStartOf="@+id/floatingActionButton"
                android:src="@mipmap/ic_launcher_round"
                app:elevation="2dp" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/floatingActionButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentTop="true"
                android:layout_marginEnd="139dp"
                android:layout_marginRight="30dp"
                android:src="@mipmap/ic_launcher" />

        </RelativeLayout>


    </RelativeLayout>


</RelativeLayout>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

If you like to Use ConstraintLayout try:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!--UpperLayer-->
    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@android:color/black"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </LinearLayout>

    <!--LowerLayer-->
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@android:color/darker_gray"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout"
        app:layout_constraintStart_toStartOf="@+id/linearLayout"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout">


    </LinearLayout>

    <!--MiddleLayer-->
    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout2"
        app:layout_constraintStart_toStartOf="@+id/linearLayout2"
        app:layout_constraintTop_toTopOf="@+id/linearLayout2">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:src="@android:drawable/ic_menu_add" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@android:drawable/ic_menu_add" />
    </LinearLayout>


</android.support.constraint.ConstraintLayout>

It Outputs:

Image Using ConstraintLayout

Note: Your UpperLayer and LowerLayer can be any Layout View, not fixed to LinearLayout

Firoz Memon
  • 4,282
  • 3
  • 22
  • 32