Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

center only icons (not text also) horizontally and vertically on a button

Tags:

android

xml

I have 3 buttons at the bottom of an app im creating, and I'm just trying to use some stock android icons instead of text or a combination of both. There is the andoid:drawableStart / top / bottom / etc commands but I just would like these icons to appear smack dab in the middle. There seems to be no easy solution for this? Here is what I am working with:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/calm"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".PiktuurMain" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" >

        <Button
            android:id="@+id/takepic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/round" />

        <Button
            android:id="@+id/editpic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_weight="1"
            android:background="@drawable/round" />

        <Button
            android:id="@+id/sharepic"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/round"
            android:drawableStart="@android:drawable/ic_dialog_email" />
    </LinearLayout>
</RelativeLayout>
like image 326
erp Avatar asked Feb 11 '14 04:02

erp


1 Answers

You can use MaterialButton. It has more advantages than something else. like the ripple effect, theme, icon tint, shape appearance, and so on.

<com.google.android.material.button.MaterialButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="0dp"
    app:icon="@drawable/ic_baseline_sports_soccer_24"
    app:iconPadding="0dp" />

<androidx.appcompat.widget.AppCompatImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_baseline_sports_soccer_24" />

enter image description here

Also, you should set android:padding="Xdp" to get suit width.

like image 113
beigirad Avatar answered Sep 26 '22 19:09

beigirad