1. 程式人生 > >安卓SlideMenu 仿QQ 主頁側滑選單

安卓SlideMenu 仿QQ 主頁側滑選單

先上圖
這裡寫圖片描述

這裡寫圖片描述

仿qq 5.0

Activity 程式碼

package custom.community.com.mydemo;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;

import com.lemonade.widgets.slidesidemenu.SlideSideMenuTransitionLayout;

import
custom.community.com.mydemo.utils.CircleImageView; public class MainActivity extends AppCompatActivity { private SlideSideMenuTransitionLayout mSlideSideMenu; private CircleImageView head_icon; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initWindow(); // Grab the widget
mSlideSideMenu = (SlideSideMenuTransitionLayout)findViewById(R.id.slide_side_menu); // Setup the toolbar head_icon = (CircleImageView) findViewById(R.id.base_toolbar); head_icon.setOnClickListener(new View.OnClickListener() { @Override public void
onClick(View view) { mSlideSideMenu.toggle(); } }); } @Override public void onBackPressed() { if (mSlideSideMenu != null && mSlideSideMenu.closeSideMenu()) { // Closed the side menu, override the default back pressed behavior return; } super.onBackPressed(); } //沉浸式狀態列 private void initWindow(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } } }

xml佈局

<?xml version="1.0" encoding="utf-8"?>
<com.lemonade.widgets.slidesidemenu.SlideSideMenuTransitionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/slide_side_menu"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/colorPrimary"
        android:padding="50dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal"
            android:layout_marginTop="40dp"
            >

            <custom.community.com.mydemo.utils.CircleImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:src="@drawable/head_icon"
                app:border_width="0dp"
                />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#ffffff"
    android:text="小c歐巴"
    android:padding="12dp"
    />
        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_marginTop="20dp"
            android:textColor="#ffffff"
            android:text="Item 1"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:text="Item 2"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:text="Item 3"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="#ffffff"
            android:text="Item 4"/>
    </LinearLayout>

    <com.lemonade.widgets.slidesidemenu.SlideSideMenuContentCardView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff">

            <!-- Optional: Tool Bar -->
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@color/colorPrimaryDark"
                android:paddingTop="26dp"
                android:paddingLeft="12dp"
                android:paddingRight="12dp"
                android:paddingBottom="12dp"
                >

                <custom.community.com.mydemo.utils.CircleImageView
                    android:id="@+id/base_toolbar"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:src="@drawable/head_icon"
                    app:border_width="0dp"
                    />

            </android.support.design.widget.AppBarLayout>

        </FrameLayout>
        <custom.community.com.mydemo.utils.CircleImageView
            android:layout_width="160dp"
            android:layout_height="160dp"
           android:layout_gravity="center"
            android:src="@drawable/head_icon"
            app:border_width="2dp"
            />
    </com.lemonade.widgets.slidesidemenu.SlideSideMenuContentCardView>
</com.lemonade.widgets.slidesidemenu.SlideSideMenuTransitionLayout>

可以根據自己的需求更改

build.gradle

   compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:22.2.0'