Search code examples
androidandroid-layoutandroid-linearlayoutandroid-xmlandroid-framelayout

How do I overlap three equally-sized views with smaller views between them?


I am trying to make three buttons equally-spaced and aligned vertically with circles overlapping between them like so:

Three buttons with circles between them

I ran into difficulties because a LinearLayout was needed to equally weight the three buttons, but overlapping views are most easily done in RelativeLayout and FrameLayout (I need to support <21 SDK, so I can't use z-index with LinearLayout).

When I put the "OR" circles in the Frame/RelativeLayouts, there's no easy way to set them at 1/3rd the view height so that they fall in between the buttons.

How do I divide a FrameLayout with the OR circles into thirds to properly place the circles?


Solution

  • I have did following xml coding and generate similar out put

        <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:weightSum="3"
            android:gravity="center"
             >
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:text="dd"
                android:background="#CCCCCC"
                android:gravity="center"
                android:layout_margin="5dp"
                android:layout_weight="1"/>
    
    
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:text="dd"
                android:layout_margin="5dp"
                android:background="#CCCCCC"
                android:gravity="center"
                android:layout_weight="1"/>
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_margin="5dp"
                android:text="dd"
                android:background="#CCCCCC"
                android:gravity="center"
                android:layout_weight="1"/>
    
        </LinearLayout>
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:weightSum="3"
            android:gravity="center"
            android:layout_height="match_parent">
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical">
                <TextView
                    android:layout_width="30dp"
                    android:background="#000000"
                    android:text="OR"
                    android:textColor="#FFFFFF"
                    android:gravity="center"
                    android:layout_height="30dp" />
            </LinearLayout>
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="vertical">
                <TextView
                    android:layout_width="30dp"
                    android:background="#000000"
                    android:text="OR"
                    android:textColor="#FFFFFF"
                    android:gravity="center"
                    android:layout_height="30dp" />
            </LinearLayout>
    
    
    
        </LinearLayout>
    
    </FrameLayout>
    

    enter image description here