Skip to content

Menu: Create

三木思 edited this page Nov 6, 2018 · 3 revisions

Builder

You need to use the Builder to build a object of menu, The following is an example of use:

TimoMenu timoMenu = new TimoMenu.Builder()
        .setGravity(Gravity.BOTTOM)
        .setMenuBackgroundDrawable(new ColorDrawable(Color.RED))
        .setMenuMargin(new Rect(10, 10, 10, 10))
        .setMenuPadding(new Rect(10, 10, 10,10))
        .setDimColor(Color.GRAY)
        .setMoveToTheFirstOneWhenShow(true)
        .addRow('ItemAnimation', ' List<TimoItemViewParameter>')
        .build();

timoMenu.show();//Will show with animation

timoMenu.showImmediately(); //Will show immediately without animation

timoMenu.dismiss(); //Will dismiss with animation

timoMenu.dismissImmediately(); //Will dismiss immediately without animation

The constructors of Builder:

Constructor Description
public Builder(Activity activity) This menu will attached to an activity, will add the menu to activity.getWindow().getDecorView()
public Builder(ViewGroup rootView) This menu will attached to a viewgroup.

The following are all the methods of the TimoMenu.Builder:

Method Description
setGravity(int gravity) Describes how this menu is positioned. Defaults to Bottom.
setMenuMargin(Rect menuMarginRect) Sets the margins for menu, in pixels.
setMenuPadding(Rect menuPaddingRect) Sets the padding for menu, in pixels.
setDimColor(int color) Set the dim color for the menu.
setMenuBackgroundDrawable(Drawable menuBackgroundDrawable) Set the background drawable of menu.
setMenuBackgroundRes(int menuBackgroundRes) Set the background resource of menu.
setMoveToTheFirstOneWhenShow(boolean moveToTheFirstOneWhenShow) Set whether to move to the first one when show, the default is true.
setDividerLine(TimoDividerLine dividerLine) Set the dividing line between each line in the menu.
setUseDefaultDividerLine(boolean use) Set whether to use the default divider line, the default is true.
setAnimation(Animation show, Animation dismiss) Set up the show animation & dismiss animation.
setUseDefaultAnimation(boolean use) Whether to use the default show animation and dismiss animation for menu when no show animation and dismiss animation are specified. The default is true.
setHeaderView(View headerView) Set a header view to the menu.
setHeaderLayoutRes(int headerLayoutRes) Set a header view to the menu.
setFooterView(View footerView) Set a footer view to the menu.
setFooterLayoutRes(int footerLayoutRes) Set a footer view to the menu.
setTimoMenuListener(TimoMenuListener timoMenuListener) Set the listener for menu, will call back the show & dismiss method.
setTimoItemTouchListener(OnTimoItemTouchListener itemTouchListener) Set the item touch listener for menu.
setTimoItemClickListener(OnTimoItemClickListener timoItemClickListener) Set the item click listener for menu.
addRow(ItemAnimation itemAnimation, List timoItemViewParameters) Add a row into the menu with the item view.
build() To build a menu.

The following are all the methods of the TimoMenu:

Method Description
show() Will show with animation.
showImmediately() Will show immediately without animation.
dismiss() Will dismiss with animation.
dismissImmediately() Will dismiss immediately without animation.
setItemAnimation(int row, ItemAnimation itemAnimation) Set the item opening animation to the corresponding row.
setMoveToTheFirstOneWhenShow(boolean moveToTheFirstOneWhenShow) Set whether to move to the first one when show, the default is true.
boolean isShowing() whether the menu is being showing.
MenuView getMenuView() Get the menu view.
List<List> getRows() Get all the items of all the rows of the menu.
List getScrollViews() Get all the rows of the menu.
setHeaderView(View headerView) Set a header view of the menu.
setHeaderLayoutRes(int headerLayoutRes) Set a header view of the menu.
setFooterView(View footerView) Set a footer view of the menu.
setFooterLayoutRes(int footerLayoutRes) Set a footer view of the menu.
addRow(ItemAnimation itemAnimation, List timoItemViewParameters) Will add a row to the menu.

Note

Considering the menu does not need to display too many items, I used 'HorizontalScrollView' to display each row.

How to build a row: you can read here

About the header & footer of menu: you can read here

About the menu listener: you can read here

Clone this wiki locally