Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What padding,margin & size should I use for a MenuItem custom layout?

I am currently using a custom layout for my MenuItem:

enter image description here

The code is basic:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_custom"
        android:actionLayout="@layout/menu_layout"
        android:showAsAction="always"/>

</menu>

While the icon size in pixel is described in the Android Design and Guidelines, I have no idea at the margin, padding, width and height I should use for this icon, so it will look legit on all devices.

My current layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/searchProgressWrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >


    <ImageButton
        android:id="@+id/ivfolder"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:scaleType="fitCenter"
        android:background="@drawable/abs__item_background_holo_dark"
        android:src="@drawable/ic_menu_archive" />


</RelativeLayout>

The big problem, is that as you can see, the width of the icon is totally wrong and is not similar at all to other MenuItems.

like image 537
Waza_Be Avatar asked Jan 11 '13 22:01

Waza_Be


People also ask

Why margin and padding are used?

Note: Margins are used to add spaces between an image and the description of that image. CSS Padding is used if we want to create a space between an element and the edge of the container or the border. It is also useful in the requirement of changing the size of the element.

What is padding and margin in HTML?

In HTML margins work the same way in giving space away from the edge of the page. Borders simply wrap the element. A border can wrap immediately around an element, or it may look further away from an element if more padding has been applied to the element. Padding provides space around the element.

What does margin 0 padding 0 mean?

margin: 0; padding: 0; } What this code does is to run over, like an elephant, every default style on the page. This can be useful as sometimes different browsers have different default stylings for different elements.


1 Answers

android:minWidth should be 56dip, android:paddingBottom and android:paddingTop should be 8dip. Found in <sdk>/platforms/android-17/data/res/values/dimens.xml:

<!-- Minimum width for an action button in the menu area of an action bar -->
<dimen name="action_button_min_width">56dip</dimen>

<!-- Vertical padding around action bar icons. -->
<dimen name="action_bar_icon_vertical_padding">8dip</dimen>
like image 139
Matthias Robbers Avatar answered Nov 15 '22 21:11

Matthias Robbers