Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add the middle Button in BottomBar layout android

I want to add facebook messenger like oversized button in the middle of my bottombar layout but confused how to add..

Facebook Messenger

I was using ahbottomnavigation library for making my bottombar.

like image 585
Doge Avatar asked Jan 16 '17 09:01

Doge


People also ask

How do you align buttons in relative layout?

Defining RelativeLayout in layout XML This is done by using the android:layout_below="@+id/textView" attribute in both the Button tags. We have aligned both the buttons from the top margin (of each other), using android:layout_alignTop="@id/button" attribute.

How do I add a button at the bottom of a linear layout?

If you want to add Buttons to the bottom of your android layout XML file you can achieve it using attribute layout_gravity on LinearLayout or TableRow layout. Below your Parent Layout tag add a LinearLayout or TableRow with attribute android:layout_gravity="bottom".


1 Answers

I just tried to make it simple, not professional type. Look here:

BottomSheetLayout file - tv.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:bottom="2dp"
    android:left="2dp"
    android:right="2dp"
    android:top="15dp">
    <shape android:shape="rectangle">
        <solid android:color="@color/colorPrimary" />
    </shape>
</item>

<item
    android:width="70dp"
    android:height="70dp"
    android:gravity="top|center">
    <shape android:shape="oval">
        <solid android:color="@color/colorPrimaryDark" />

    </shape>
</item>

ActivityLayout - activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
    android:layout_height="80dp"
    android:layout_width="match_parent"
    android:background="@drawable/tv"
    android:gravity="bottom"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:id="@+id/view">

</RelativeLayout>

<ImageButton
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginStart="34dp"
    android:layout_alignBottom="@+id/imageButton"
    android:layout_toEndOf="@+id/imageButton"
    android:id="@+id/imageButton3" />

<ImageButton
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:background="@drawable/ic_ring"
    android:layout_alignTop="@+id/view"
    android:layout_centerHorizontal="true"
    android:id="@+id/imageButton" />

<ImageButton
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginStart="33dp"
    android:id="@+id/imageButton2"
    android:layout_alignBottom="@+id/imageButton3"
    android:layout_toEndOf="@+id/imageButton3" />

<ImageButton
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:id="@+id/imageButton4"
    android:layout_marginEnd="34dp"
    android:layout_alignBottom="@+id/imageButton"
    android:layout_toStartOf="@+id/imageButton" />

<ImageButton
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:id="@+id/imageButton5"
    android:layout_alignParentBottom="true"
    android:layout_toStartOf="@+id/imageButton4"
    android:layout_marginEnd="33dp"
    android:layout_marginBottom="10dp"/>

</RelativeLayout>

Output:

enter image description here

Change value and design as per your idea.

Example is just a demo and does not contain exact answer asked by OP. Its just a hard coded dummy.

like image 190
W4R10CK Avatar answered Sep 19 '22 20:09

W4R10CK