Use of DrawerLayout and background settings to remove shadows


drawerLayout is a control in the Support Library package that implements the side-sliding menu effect. It can be said that drawerLayout is the product of Google's reference after the emergence of third-party controls such as MenuDrawer. drawerLayout is divided into two parts: side menu and main content area. The side menu can be expanded and hidden according to gestures (drawerLayout's own characteristics)

. It is relatively simple to use:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/weather_drawer">

    <include layout="@layout/your main layout layout"/>
    <!--The main layout is written here-->

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:id="@+id/weather_left_drawer"
        android:orientation="vertical"
        android:layout_gravity="left"
        android:background="@color/black">
        <ListView
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:id="@+id/left_drawer_listview"
            android:background="@color/black">
        </ListView>
    </LinearLayout>
    <!--Left drawer-->

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:id="@+id/weather_right_drawer"
        android:orientation="vertical"
        android:layout_gravity="right"
        android:background="@color/black">
        <ListView
            android:layout_width="200dp"
            android:layout_height="match_parent"
            android:id="@+id/right_drawer_listview"
            android:background="@color/black">
        </ListView>
    </LinearLayout>
    <!--Right drawer-->
</android.support.v4.widget.DrawerLayout>



The main layout is placed first, the drawer layout is placed at the back, android:layout_gravity="xxx" , this attribute identifies the drawer, here we need to complain, the as code prompt does not have this attribute. The value left or right of this property identifies whether your drawer is drawn from the left or right.
At this time, some students may ask, can the main layout be placed in the back, or can it be placed in the middle, anyway, the drawerlayout relies on the layout_gravity to identify the layout_gravity.
Answer: No. In the above layout, if the main layout is placed between the two drawers, there will be a bug: if the drawer on the left is drawn, it cannot be drawn back! (The one on the right has no effect) You can try it yourself.


There is also a problem. By default, when the drawer is drawn out, there will be a layer of shadow covering the main layout, as shown below:


 

How to solve this problem is quite simple.

drawerLayout.setScrimColor(Color.TRANSPARENT);

After adding the code, the effect is shown in the following figure:


 

Well, the basic usage of drawerlayout and some small problems are mentioned here, I will add what I think of. If you have any questions, please leave a message.
 
 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641989&siteId=291194637