大叔帮帮忙是最近比较火的一个android应用,闲着没事,决定高仿一下,可是忙活了半天,主要是大部分时间都在玩,中午写着写着看起了比赛(骑士VS湖人,23VS24),绝佳嘘头啊,还好今天我科今天比较牛逼,老詹也是牛逼,作为一个不讨厌老詹的科密,看着两人场上有说有笑,心里还是蛮开心的。
好了,闲话shaoxu,还是先看下大叔帮帮忙的主界面UI吧,首先定义色彩主调就是黄色,像QQ的蓝,陌陌的黑,这个还是比较罕见,不过还是挺漂亮的。
个人感觉,这个侧滑菜单还是比较帅气。
开始做吧,首先用了下第三方开源包menudrawer;
对于菜单界面xml布局代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/ll_menu_info"
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="@string/user"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#eee" />
<LinearLayout
android:id="@+id/ll_menu_favor"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/button_favor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="@string/favor"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_menu_lantern"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/button_lantern" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="@string/lantern"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_menu_msg"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/button_msg" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="@string/msg"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#eee" />
<LinearLayout
android:id="@+id/ll_menu_visitor"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/button_visitor" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="@string/visitor"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_menu_friend"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:src="@drawable/button_friend" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:text="@string/friend"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
MainActivity先设置下actionbar样式
private void initBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar bar = getActionBar();
Drawable drawable = getResources().getDrawable(
R.drawable.actionbar_bg);
bar.setBackgroundDrawable(drawable);
bar.setDisplayUseLogoEnabled(false);
bar.setDisplayHomeAsUpEnabled(false);
}
}
menudrawer = MenuDrawer.attach(this, MenuDrawer.Type.OVERLAY);
menudrawer.setContentView(R.layout.activity_main);
menudrawer.setMenuView(R.layout.activity_left);
menudrawer.setSlideDrawable(R.drawable.btn_menu_toggle);
menudrawer.setDrawerIndicatorEnabled(true);
menudrawer.peekDrawer(500, 0);
设置滑动菜单菜单界面及内容界面,然后设置点击显示按钮切换菜单事件:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
menudrawer.toggleMenu();
return true;
}
return super.onOptionsItemSelected(item);
}
做到这些,滑动菜单已经完成了,明天开始实现菜单点击按钮,效果图如下: