我也是在网上看到的,就来试验了一下,总体来说还不错,比较简单清新,不像别的一些比较繁琐复杂,现在的app我个人觉得都是趋于简单化,大家也可以试验一下,
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jake.smart.SmartMenu
android:id="@+id/smart_menu"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:vertical_padding="13dp"
app:outer_padding="30dp"
app:inner_padding="10dp"
app:dot_radius="2dp"
app:dot_distance="25dp"
app:bg_color="#b4282d"
app:shadow_color="#40000000"
app:dot_color="@android:color/white"/>
</RelativeLayout>```
#####menu文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_view"
android:src="@mipmap/icon_album"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="center"
android:layout_centerInParent="true"/>
</RelativeLayout>
#####MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SmartMenu smartMenu = (SmartMenu) findViewById(R.id.smart_menu);
MenuAdapter adapter = new MenuAdapter();
adapter.setListener(new ItemEventListener() {
@Override
public void onEventNotify(View view, int position, Object... data) {
switch (position) {
case 0:
toast("ALBUM");
break;
case 1:
toast("COMMENT");
break;
case 2:
toast("DRAFT");
break;
case 3:
toast("LIKE");
break;
}
}
});
smartMenu.setAdapter(adapter);
}
private void toast(String msg) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}
#####adapter
public class MenuAdapter extends BaseAdapter implements View.OnClickListener{
private int[] images = new int[]{R.mipmap.icon_album,
R.mipmap.icon_comment,
R.mipmap.icon_draft,
R.mipmap.icon_like};
private ItemEventListener listener;
public void setListener(ItemEventListener listener) {
this.listener = listener;
}
@Override
public int getCount() {
return 4;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_menu, viewGroup, false);
view.setOnClickListener(this);
view.setTag(i);
ImageView img = (ImageView) view.findViewById(R.id.image_view);
img.setImageResource(images[i]);
return view;
}
@Override
public void onClick(View view) {
if(listener!=null){
listener.onEventNotify(view,(int)view.getTag());
}
}
}
#####Listener
public interface ItemEventListener {
public void onEventNotify(View view, int position,Object... data);
}```