代码:http://download.youkuaiyun.com/detail/huangbin95487710/9259699
依赖包模式
完整运行还需要用到以下依赖包
- 支持样式属性配置
- 支持配置动画时间
- 支持配置动画半径
- 支持配置对齐方式
- 菜单按钮配置化(免代码)
<declare-styleable name="Path"> <!-- 展示序列 --> <attr name="path_menu" format="integer" /> <!-- 主按钮 --> <attr name="path_icon" format="integer" /> <!-- 主按钮动画 --> <attr name="path_icon_anim" format="boolean" /> <!-- 动画时间 --> <attr name="path_anim" format="integer" /> <!-- 动画半径 --> <attr name="path_radius" format="integer" /> <!-- 对齐方式 --> <attr name="path_mode"> <enum name="BottomLeft" value="0" /> <enum name="BottomCenter" value="1" /> <enum name="BottomRight" value="2" /> <enum name="CenterLeft" value="3" /> <enum name="CenterRight" value="4" /> <enum name="TopLeft" value="5" /> <enum name="TopCenter" value="6" /> <enum name="TopRight" value="7" /> </attr> </declare-styleable>
- 默认样式
<!-- 默认样式 --> <style name="DivPath"> <item name="path_menu">@array/path_menu</item> <item name="path_icon">@drawable/view_path_button</item> <item name="path_icon_anim">true</item> <item name="path_anim">300</item> <item name="path_radius">120</item> <item name="path_mode">BottomCenter</item> </style>
- 属性配置例子
- 布局文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <General.View.PathLayout android:id="@+id/path" style="@style/MyDivPath" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" /> </RelativeLayout>
- 样式
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- 自定义序列 --> <integer-array name="div_path_menu"> <item>-1</item> <item>@drawable/path_question</item> <item>@drawable/path_photo</item> <item>@drawable/path_people</item> <item>@drawable/path_pet</item> <item>-1</item> </integer-array> <style name="MyDivPath" parent="@style/DivPath"> <item name="path_menu">@array/div_path_menu</item> <item name="path_icon">@drawable/path_menu</item> <item name="path_anim">300</item> <item name="path_radius">180</item> <item name="path_mode">BottomCenter</item> </style> </resources>
- 监听点击事件
PathLayout mPathLayout = (PathLayout) this.findViewById(R.id.path); mPathLayout.show(); OnClickListener mListener = new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int mId = v.getId(); if (mId == R.drawable.path_pet) { MyLog.show(PathActivity.this, "path_pet"); } else if (mId == R.drawable.path_photo) { MyLog.show(PathActivity.this, "path_photo"); } else if (mId == R.drawable.path_people) { MyLog.show(PathActivity.this, "path_people"); } else if (mId == R.drawable.path_question) { MyLog.show(PathActivity.this, "path_question"); } } }; mPathLayout.setButtonsOnClickListener(mListener);
- 效果图