android 使用DrawerLayout实现滑动抽屉
2016-08-02 20:49
585 查看
实现滑动效果可能有多种方法,比如SliddingDrawer,NavigationDrawer,SliddingMenu,DrawerLayout等
本文实现一个简单的滑动抽屉效果的demo(android studio 环境)
上代码:
xml布局代码:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 抽屉隐藏时显示的布局 S-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="课程表"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<!-- 抽屉隐藏时显示的布局 E-->
<!--抽屉里的布局在这里写 S-->
<LinearLayout
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
<ListView android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</LinearLayout>
<!--抽屉里的布局在这里写 E-->
</android.support.v4.widget.DrawerLayout>
以上的布局可以根据需要自己改动,第一个布局是在未显示抽屉时要显示的界面,第二个布局是抽屉滑出的界面
MainActivity.java
package slidingdrawer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
源码下载
效果图
本文实现一个简单的滑动抽屉效果的demo(android studio 环境)
上代码:
xml布局代码:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 抽屉隐藏时显示的布局 S-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="课程表"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<!-- 抽屉隐藏时显示的布局 E-->
<!--抽屉里的布局在这里写 S-->
<LinearLayout
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
<ListView android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</LinearLayout>
<!--抽屉里的布局在这里写 E-->
</android.support.v4.widget.DrawerLayout>
以上的布局可以根据需要自己改动,第一个布局是在未显示抽屉时要显示的界面,第二个布局是抽屉滑出的界面
MainActivity.java
package slidingdrawer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
源码下载
效果图
相关文章推荐
- Android 使用DrawerLayout实现抽屉效果的导航菜单
- 【Android界面实现】使用ActionBar和DrawerLayout纯原生控件,实现侧滑栏和滑动Tab界面
- Android使用CoordinatorLayout和BottomSheetBehavior实现滑动效果(底部抽屉)
- Android抽屉菜单DrawerLayout的实现案例
- Android 左右滑动菜单 DrawerLayout简单实现
- Android使用DrawerLayout创建左右两个抽屉菜单
- Android典型界面设计(5)——使用SlidingMenu和DrawerLayout分别实现左右侧边栏
- Android组件之DrawerLayout实现抽屉菜单
- android抽屉DrawerLayout的使用
- [AndroidUI]使用DrawerLayout实现侧滑菜单
- Android使用DrawerLayout创建左右两个抽屉菜单
- Android:使用Toolbar + DrawerLayout快速实现菜单侧滑
- android开发游记:DrawerLayout 实现抽屉效果的导航菜单
- Android使用DrawerLayout创建左右两个抽屉菜单 推荐
- Android使用DrawerLayout实现仿QQ双向侧滑菜单
- 使用DrawerLayout和SlidingDrawer实现的抽屉效果
- Android使用DrawerLayout创建左右两个抽屉菜单
- [Android基础知识] 之二十: 侧滑菜单DrawerLayout(抽屉布局)实现
- Android开发_DrawerLayout实现抽屉布局
- Android 使用Drawerlayout仿网易新闻客户端抽屉模式