android 侧滑栏

界面

界面布局:
`<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/dl_main"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".activity.MainActivity">

<include layout="@layout/music_main"></include>



       </LinearLayout>
       <LinearLayout
           android:layout_marginTop="20dp"
           android:gravity="center"
           android:orientation="horizontal"
           android:layout_width="wrap_content"
           android:layout_height="45dp">
           <ImageView
               android:layout_marginRight="40dp"
               android:layout_marginLeft="20dp"
               android:src="@drawable/ic_menu_settings"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>
           <TextView
               android:text="@string/menu_setting"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>
       </LinearLayout>
       <View
           android:background="@color/grey"
           android:layout_marginRight="20dp"
           android:layout_marginLeft="20dp"
           android:layout_width="match_parent"
           android:layout_height="1dp"/>
       <LinearLayout
           android:gravity="center"
           android:orientation="horizontal"
           android:layout_width="wrap_content"
           android:layout_height="45dp">
           <ImageView
               android:layout_marginRight="40dp"
               android:layout_marginLeft="20dp"
               android:src="@drawable/ic_menu_night"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>
           <TextView
               android:text="@string/menu_night"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>
       </LinearLayout>
       <View
           android:background="@color/grey"
           android:layout_marginRight="20dp"
           android:layout_marginLeft="20dp"
           android:layout_width="match_parent"
           android:layout_height="1dp"/>
       <LinearLayout

           android:gravity="center"
           android:orientation="horizontal"
           android:layout_width="wrap_content"
           android:layout_height="45dp">
           <ImageView
               android:layout_marginRight="40dp"
               android:layout_marginLeft="20dp"
               android:src="@drawable/ic_menu_timer"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>
           <TextView
               android:text="@string/menu_timer"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>
       </LinearLayout>
   </LinearLayout>

   <View
       android:background="@color/grey_300"
       android:layout_below="@id/ll_set"
       android:layout_above="@+id/ll_about"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"/>
   <LinearLayout
       android:id="@+id/ll_about"
       android:layout_marginBottom="20dp"
       android:layout_above="@id/ll_exit"
       android:gravity="center"
       android:orientation="horizontal"
       android:layout_width="wrap_content"
       android:layout_height="45dp">
       <ImageView
           android:layout_marginRight="40dp"
           android:layout_marginLeft="20dp"
           android:src="@drawable/ic_menu_about"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>
       <TextView
           android:text="@string/menu_about"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>
   </LinearLayout>
   <View
       android:background="@color/grey"
       android:layout_marginRight="20dp"
       android:layout_marginLeft="20dp"
       android:layout_above="@id/ll_exit"
       android:layout_width="match_parent"
       android:layout_height="1dp"/>
   <LinearLayout
       android:layout_marginTop="10dp"
       android:id="@+id/ll_exit"
       android:layout_marginBottom="20dp"
       android:gravity="center"
       android:layout_alignParentBottom="true"
       android:orientation="horizontal"
       android:layout_width="wrap_content"
       android:layout_height="45dp">
       <ImageView
           android:layout_marginRight="40dp"
           android:layout_marginLeft="20dp"
           android:src="@drawable/ic_menu_exit"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>
       <TextView
           android:text="@string/menu_exit"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"/>
   </LinearLayout>

</androidx.drawerlayout.widget.DrawerLayout>`

private DrawerLayout dl_main;
//利用点击事件打开侧滑栏
dl_main.openDrawer(Gravity.LEFT);

posted @ 2021-11-19 23:02  九块  阅读(33)  评论(0编辑  收藏  举报