侧划菜单的应用

package com.bwie.shimeice20151105;

import android.os.Bundle;
import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;

public class MainActivity extends ActivityGroup {

    private SlidingMenuView slidingMenuView;
    private ViewGroup frambody;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找控件
        slidingMenuView = (SlidingMenuView) findViewById(R.id.slidingmenu);
        frambody = (ViewGroup) findViewById(R.id.sliding_center_tab);
        showDefaultTab();
        
    }
/**
 * 设置默认展示界面
 */
    private void showDefaultTab() {
        // TODO Auto-generated method stub
        Intent intent=new Intent(this,HomeActivity.class);
        View v=getLocalActivityManager().startActivity(HomeActivity.class.getName(), intent).getDecorView();
        frambody.removeAllViews();
        frambody.addView(v);
    }
/**
 * 主页按钮监听
 */
    public void showHome(View view){
        Intent intent=new Intent(this,HomeActivity.class);
        View v=getLocalActivityManager().startActivity(HomeActivity.class.getName(), intent).getDecorView();
        frambody.removeAllViews();
        frambody.addView(v);
    }
    /**
     * 设置按钮监听
     */
        public void showSet(View view){
            Intent intent=new Intent(this,SetActivity.class);
            View v=getLocalActivityManager().startActivity(SetActivity.class.getName(), intent).getDecorView();
            frambody.removeAllViews();
            frambody.addView(v);
        }
/**
 * 隐藏监听
 */
    public void hithMenu(View view){
        slidingMenuView.snapToScreen(1);
    }
/**
 * 显示左侧菜单
 */
    public void showLeftMenu(View view){
        slidingMenuView.snapToScreen(0);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

 

layout中的布局效果

 

<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"
    tools:context=".MainActivity" >
    <com.bwie.shimeice20151105.SlidingMenuView
        android:id="@+id/slidingmenu"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <LinearLayout
        android:id="@+id/sliding_left_tab"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@drawable/ph4"
        android:orientation="vertical"
        >
        <Button
            
            android:id="@+id/sliding_left_home"
            android:onClick="showHome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="主页"
            />
         <Button
            
            android:id="@+id/sliding_left_set"
            android:onClick="showSet"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="设置"
            />
    </LinearLayout>
    <FrameLayout
        android:id="@+id/sliding_center_tab"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        ></FrameLayout>
    <LinearLayout
        android:id="@+id/sliding_rigth_tab"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:background="@drawable/ph6"
        android:orientation="vertical"
        >
        <Button
            android:id="@+id/sliding_rigth_hite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="hithMenu"
            android:text="隐藏侧滑菜单"
            />
        <Button
             android:id="@+id/sliding_rigth_hite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="showLeftMenu"
            android:text="显示左侧菜单"
            />
    </LinearLayout>
        
    </com.bwie.shimeice20151105.SlidingMenuView>

   
</RelativeLayout>

 

posted @ 2015-11-29 20:50  玩弓射雕郭大侠  阅读(148)  评论(0编辑  收藏  举报