android原生侧滑功能DrawLayout

android原生侧滑功能DrawLayout

导读:*项目需要实现侧滑功能,准备用fragment,或者其他的方式,要到网上一大堆的资料。居然发现Android原生就有,它是DrawLayout。

场景

项目需要实现这个功能

这里写图片描述

实现方法

代码展示

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.telehot.sll.df_app.MainActivity">

    <RelativeLayout
        android:id="@+id/rl_connet"
        android:layout_width="match_parent"
        android:layout_height="match_parent">        
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/rl_left"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:background="@drawable/bg_left"
        android:layout_gravity="start">     

    </RelativeLayout>

</android.support.v4.widget.DrawerLayout>

代码分析

1.布局用DrawerLayout为根部局。

2.子布局有两个RelativeLayout,前一个放主页内容,后一个放左侧内容。

3.注意点,侧滑布局的这个属性android:layout_gravity=”start”表示这是左侧栏,若=end就是右侧栏了。

猜你喜欢

转载自blog.csdn.net/song_liang_liang/article/details/81221022