drawerLayout不在边缘处 ,左侧划出具体实现方式
时间: 2024-02-01 07:15:37 浏览: 25
要让 `DrawerLayout` 不在边缘处,可以使用 `android:layout_marginStart` 属性来设置左侧的间距。
具体实现方式如下:
1. 在布局文件中添加 `DrawerLayout` 和主界面布局:
```
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 主界面布局 -->
<LinearLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- ... -->
</LinearLayout>
<!-- 左侧抽屉菜单布局 -->
<LinearLayout
android:id="@+id/drawer_menu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:orientation="vertical">
<!-- ... -->
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
```
2. 设置 `DrawerLayout` 的 `android:layout_marginStart` 属性为你想要的距离,比如 50dp:
```
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="50dp">
<!-- ... -->
</android.support.v4.widget.DrawerLayout>
```
这样就可以让抽屉菜单不在屏幕边缘处了。