Clash Of Clan 喜欢 NavigationView 拉箭头

Clash Of Clan like NavigationView Pull Arrow

我想创建一个自定义视图,它在侧抽屉关闭时保持可见,但通过拉动它,抽屉会滑动。 我在非常流行的游戏《部落冲突》中看到过这样的情况,如下图所示:

现在我想知道是否有任何方法可以通过使用 DrawerLayoutNavigationView 来实现同样的目的?

最后我通过添加 addDrawerListener 并相应地翻译 HANDLE 实现了这一点。

这是我的 ACTIVITY:

import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

/**
 * @author Meet Vora
 */
public class PullSliderActivity extends AppCompatActivity {

    private DrawerLayout drawerLayout;
    private View viewPuller;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pull_slider);

        drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        viewPuller = findViewById(R.id.viewPuller);

        drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                viewPuller.setTranslationX(drawerView.getX() + drawerView.getWidth());
            }

            @Override
            public void onDrawerOpened(View drawerView) {

            }

            @Override
            public void onDrawerClosed(View drawerView) {

            }

            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });
    }

}

这是布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/MyHelpActivityTheme">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:openDrawer="start">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#49fcea"
            android:gravity="center"
            android:text="This is MAIN Screen"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:textStyle="bold"/>

        <android.support.design.widget.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#223344"
                android:gravity="center"
                android:text="This is NAVIGATION View"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:textStyle="bold"/>

        </android.support.design.widget.NavigationView>
    </android.support.v4.widget.DrawerLayout>

    <TextView
        android:id="@+id/viewPuller"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="#5f97cf"
        android:clickable="false"
        android:gravity="center"
        android:padding="4dp"
        android:text="N\n.\nV\nI\nE\nW"
        android:textColor="@color/white"
        android:textSize="10sp"
        android:textStyle="bold"/>
</RelativeLayout>