Android开源界面库--ResideMenu用法
网上关于ResideMenu用法的教程很多,但基本上全是从Github上copy下来的,Gitbub上给出的了对应的demo,但是由于我的IDE原因吧,demo一直导入不成功。为此自己又捣鼓了一翻,终于运行成功ResideMenu的真容。






package com.example.residemenutest;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import com.special.ResideMenu.ResideMenu;
import com.special.ResideMenu.ResideMenuItem;
public class MenuActivity extends FragmentActivity implements View.OnClickListener{
private ResideMenu resideMenu;
private MenuActivity mContext;
private ResideMenuItem itemHome;
private ResideMenuItem itemProfile;
private ResideMenuItem itemCalendar;
private ResideMenuItem itemSettings;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = this;
setUpMenu();
changeFragment(new HomeFragment());
}
private void setUpMenu() {
// attach to current activity;
resideMenu = new ResideMenu(this);
resideMenu.setBackground(R.drawable.menu_background);
resideMenu.attachToActivity(this);
resideMenu.setMenuListener(menuListener);
// create menu items;
itemHome = new ResideMenuItem(this, R.drawable.icon_home, "Home");
itemProfile = new ResideMenuItem(this, R.drawable.icon_profile, "Profile");
itemCalendar = new ResideMenuItem(this, R.drawable.icon_calendar, "Calendar");
itemSettings = new ResideMenuItem(this, R.drawable.icon_settings, "Settings");
itemHome.setOnClickListener(this);
itemProfile.setOnClickListener(this);
itemCalendar.setOnClickListener(this);
itemSettings.setOnClickListener(this);
resideMenu.addMenuItem(itemHome);
resideMenu.addMenuItem(itemProfile);
resideMenu.addMenuItem(itemCalendar);
resideMenu.addMenuItem(itemSettings);
findViewById(R.id.title_bar_menu).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
resideMenu.openMenu();
}
});
}
@Override
public void onClick(View view) {
if (view == itemHome){
changeFragment(new HomeFragment());
}else if (view == itemProfile){
changeFragment(new ProfileFragment());
}else if (view == itemCalendar){
changeFragment(new CalendarFragment());
}else if (view == itemSettings){
changeFragment(new SettingsFragment());
}
resideMenu.closeMenu();
}
private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() {
@Override
public void openMenu() {
Toast.makeText(mContext, "Menu is opened!", Toast.LENGTH_SHORT).show();
}
@Override
public void closeMenu() {
Toast.makeText(mContext, "Menu is closed!", Toast.LENGTH_SHORT).show();
}
};
private void changeFragment(Fragment targetFragment){
resideMenu.clearIgnoredViewList();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.main_fragment, targetFragment, "fragment")
.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
// What good method is to access resideMenu?
public ResideMenu getResideMenu(){
return resideMenu;
}
}
它只要是声明了一个ResideMenu,并为这个ResideMenu进行了一些初始化。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/white"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layout_top">
<ImageView
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#2ea3fe"/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="28dp"
android:layout_height="28dp"
android:background="@drawable/titlebar_menu_selector"
android:id="@+id/title_bar_menu"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="7dp"
android:text="RESideMenu DEMO"
android:textSize="24sp"
android:textColor="#999999"
android:layout_gravity="center"/>
</FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#ebebeb"/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main_fragment">
</FrameLayout>
</LinearLayout>
接下来是四个Fragment,它们只是一些简单的展示所以很简单,如比较漂亮的HomeFragment,代码如下:
package com.example.residemenutest;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.special.ResideMenu.ResideMenu;
/**
* User: special
* Date: 14-13-20
* Time: 下午1:33
* Mail: cym@saymagic.cn
*/
public class HomeFragment extends Fragment {
private View parentView;
private ResideMenu resideMenu;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
parentView = inflater.inflate(R.layout.home, container, false);
setUpViews();
return parentView;
}
private void setUpViews() {
MenuActivity parentActivity = (MenuActivity) getActivity();
resideMenu = parentActivity.getResideMenu();
parentView.findViewById(R.id.btn_open_menu).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
resideMenu.openMenu();
}
});
// add gesture operation's ignored views
FrameLayout ignored_view = (FrameLayout) parentView.findViewById(R.id.ignored_view);
resideMenu.addIgnoredView(ignored_view);
}
}
剩下的代码不一一展示了,都很简单,ResideMenu其实封装的已经很好了,你可以用调用residemenu的openMenu()打开这个菜单,closeMenu()关闭这个菜单等等。最后,把本文所需的ResideMenu文件和自己写的demo源码分享出来。
转载请注明---曹艳明个人博客:www.saymagic.cn.
Android开源界面库--ResideMenu用法的更多相关文章
- C++100款开源界面库[转]
(声明:Alberl以后说到开源库,一般都是指著名的.或者不著名但维护至少3年以上的.那些把代码一扔就没下文的,Alberl不称之为开源库,只称为开源代码.这里并不是贬低,像Alberl前面那个系列的 ...
- C++ 100款开源界面库 (10)
(声明:Alberl以后说到开源库,一般都是指著名的.或者不著名但维护至少3年以上的.那些把代码一扔就没下文的,Alberl不称之为开源库,只称为开源代码.这里并不是贬低,像Alberl前面那个系列的 ...
- 仿迅雷播放器教程 -- C++ 100款开源界面库 (10)
(声明:Alberl以后说到开源库,一般都是指著名的.或者不著名但维护至少3年以上的.那些把代码一扔就没下文的,Alberl不称之为开源库,只称为开源代码.这里并不是贬低,像Alberl前面那个系 ...
- 我的Android进阶之旅------>【强力推荐】Android开源图表库XCL-Charts版本发布及展示页
因为要做图表相关的应用,后来百度发现了一个很好的Android开源图表库(XCL-Charts is a free charting library for Android platform.) 下面 ...
- Android开源图表库XCL-Charts版本号公布及展示页
XCL-Charts V2.1 Android开源图表库(XCL-Charts is a free charting library for Android platform.) XCL-Charts ...
- Android开源图表库介绍
XCL-Charts XCL-Charts V1.8 Android开源图表库(XCL-Charts is a free charting library for Android platfo ...
- 曲线控件我一直用codeproject上的那几个(C++ 100款开源界面库)
Alberl#23楼[楼主] 2013-11-04 11:47 Alberl @baita00引用看了大神的教程,真的不错,学习了很多东西,^_^.这节教程里,大神好像在找曲线控件,是吗?大神有什特殊 ...
- WPF开源界面库及控件
WPF开源项目 WPF有很多优秀的开源项目,我以为大家都知道,结果,问了很多人,其实他们不知道.唉,太可惜了! 先介绍两个比较牛逼的界面库 1.MaterialDesignInXamlToolkit ...
- WPF开源界面库
WPF开源项目 WPF有很多优秀的开源项目,我以为大家都知道,结果,问了很多人,其实他们不知道.唉,太可惜了! 先介绍两个比较牛逼的界面库 1.MaterialDesignInXamlToolkit ...
随机推荐
- Aveva Marine C# 二次开发入门001
1# 引用 C:\AVEVA\Marine\OH12.1.SP4\Aveva.ApplicationFramework.dll C:\AVEVA\Marine\OH12.1.SP4\Aveva.App ...
- 解决tomcat端口冲突
1.根据8080端口号查找占用8080端口的进程 netstat -ano|findstr " 进程id:6352 2.根据进程ID查找进程名字 tasklist|findstr " ...
- opencv 单目标模板匹配(只适用于模板与目标尺度相同)
#include <iostream> #include "opencv/cv.h" #include "opencv/cxcore.h" #inc ...
- kali入侵服务器的那一套实战
dnsenum -enum xxxxx.com 枚举出网站的所有域名和服务器的ip地址 打开百度查询ip地址的所在地 whatweb xxxx.com 查看那些网站入口可以访问 以状 ...
- vue transtion 实现分析
这是我用js和css3,实现的vue transition组件相同的效果核心js var btn = document.getElementById('btn'); var box = null bt ...
- 1-10000以内的完数(js)
//1-10000以内的完数 //完数:因子之和相加等于这个数 //例如:6的因子为1,2,3:1+2+3=6 // 6 // 28 // 496 // 8128 let sum = 0, i, j; ...
- 【转载】linux SUID SGID
作者:sparkdev 出处:http://www.cnblogs.com/sparkdev/ setuid 和 setgid 分别是 set uid ID upon execution 和 set ...
- ubuntu - 14.04,安装Git(源代码管理工具)
在shell中执行:sudo apt-get install git-core
- Redis-String常用命令
Redis-String常用命令 set key value- 设置Key-value键值对 get key 获取指定key对应的值 append key value 在指定key对应值的后面追加va ...
- MySQL数据库笔记五:多表查询
1.表与表之间的关系 一对一:用户表和身份信息表,用户表是主表 例如:男人表 .女人表 create table man( mid int primary key auto_increment, mn ...