
Moving and resizing DrawerLayout’s content on sliding
You can do this by translating and scaling the content View in the onDrawerSlide() method of a DrawerListener on your DrawerLayout. Since the content View itself is resizing, and there’s a separate TextView that appears in the bottom right corner, we’ll stick both of these in another holder ViewGroup. If that label TextView isn’t needed, the holder ViewGroup can be omitted, as well. A basic DrawerLayout setup for the example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<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" android:background="#222222"> <RelativeLayout android:id="@+id/holder" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="#E97411" /> <ImageView android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#EEEEEE" android:src="@drawable/ic_launcher" /> </LinearLayout> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:visibility="gone" android:textSize="26dp" android:text="My App" /> </RelativeLayout> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#555555" /> </android.support.v4.widget.DrawerLayout> |
The […]