最近公司项目需求,需要做一个弧形动画菜单的效果,在网上找了很久终于找到了自己想要的效果,现在记录下来以方便自己和大家学习,效果图如下:
首先需要添加依赖:
compile 'csy.menu.satellitemenulib:SatelliteMenu:1.0.3'
在布局中的使用如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.a31210.myeventbus.MenuActivity">
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="45dp"
android:textColor="#ffffff"
android:textSize="18sp"
android:gravity="center"
android:text="弧形动画菜单"
android:background="@color/colorPrimary"/>
<csy.menu.satellitemenulib.view.SatelliteMenu
android:id="@+id/mStatelliteMenuLeftTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="45dp"
app:menu_postion="left_top"
app:radius="150dp"
app:menu_image_width="45dp"
app:menu_item_image_width="50dp"
app:menu_item_text_size="4sp"
app:menu_item_text_color="@color/colorPrimary">
</csy.menu.satellitemenulib.view.SatelliteMenu>
</RelativeLayout>
代码中的使用如下:
public class MenuActivity extends AppCompatActivity {
private SatelliteMenu mStatelliteMenuLeftTop;
private List<Integer>imgList=new ArrayList<>();
private List<String>textList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_menu);
imgList.add(R.mipmap.ic_launcher_round);
imgList.add(R.mipmap.ic_launcher_round);
imgList.add(R.mipmap.ic_launcher_round);
imgList.add(R.mipmap.ic_launcher_round);
textList.add("音乐");
textList.add("电视");
textList.add("电影");
textList.add("新闻");
mStatelliteMenuLeftTop= (SatelliteMenu) findViewById(R.id.mStatelliteMenuLeftTop);
mStatelliteMenuLeftTop.getmBuilder()
.setMenuImage(R.mipmap.ic_launcher_round)
.setMenuItemImageResource(imgList)
.setMenuItemNameTexts(textList)
.setOnMenuItemClickListener(new SatelliteMenu.OnMenuItemClickListener() {
@Override
public void onClick(View view, int postion) {
Toast.makeText(MenuActivity.this,"点击了菜单"+postion,Toast.LENGTH_LONG).show();
}
}).creat();
}
}