zoukankan      html  css  js  c++  java
  • 开源控件slidingmenu的使用

    在github.com网站搜索slidingmenu后https://github.com/jfeinstein10/SlidingMenu

    下载demo,导入library到你的项目中,添加到你项目的依赖中使用:

    package com.loaderman.slidingmenudemo;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            // configure the SlidingMenu
            SlidingMenu menu = new SlidingMenu(this);
            menu.setMode(SlidingMenu.LEFT);
            // 设置触摸屏幕的模式
            menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
            menu.setShadowWidthRes(R.dimen.shadow_width);
            menu.setShadowDrawable(R.drawable.shadow);
    
            // 设置滑动菜单视图的宽度
            menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
            // 设置渐入渐出效果的值
            menu.setFadeDegree(0.35f);
            /**
             * SLIDING_WINDOW will include the Title/ActionBar in the content
             * section of the SlidingMenu, while SLIDING_CONTENT does not.
             */
            //把滑动菜单添加进所有的Activity中,可选值SLIDING_CONTENT , SLIDING_WINDOW
            menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
            //为侧滑菜单设置布局
            menu.setMenu(R.layout.leftmenu);
        }
    }
    

     activity_main.xml

    <RelativeLayout
        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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="主界面"
            />
    
    </RelativeLayout>
    

     drawable下创建shadow.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <gradient
            android:endColor="#33000000"
            android:centerColor="#11000000"
            android:startColor="#00000000" />
    
    </shape>
    

     侧边栏布局leftmenu.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Hello Sliding Menu!" />
    
    </LinearLayout>
    

    dimens.xml

       <dimen name="slidingmenu_offset">80dp</dimen>
        <dimen name="shadow_width">15dp</dimen>
    

     实现效果:

  • 相关阅读:
    Android(java)学习笔记68:使用proguard混淆android代码
    SGU 194 Reactor Cooling
    关于流量有上下界的网络流问题的求解
    关于最小割的求解方法
    HDU 5311 Hidden String
    POJ 3548 Restoring the digits
    POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater
    ZOJ 1967 POJ 2570 Fiber Network
    HDU 1969 Pie
    HDU 1956 POJ 1637 Sightseeing tour
  • 原文地址:https://www.cnblogs.com/loaderman/p/6544039.html
Copyright © 2011-2022 走看看