短视频带货源码模仿QQ 测滑菜单

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/mainLayout"
    tools:context="com.chengxing.comchenxingnetapp.MainActivity">

    <RelativeLayout
        android:id="@+id/right"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/show"
            android:onClick="onClick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/app_name" />
    </RelativeLayout>



    <RelativeLayout
        android:id="@+id/main_fl_drawer"
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:paddingTop="0dp">

        <TextView
            android:background="@color/colorPrimaryDark"
            android:text="@string/app_name"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>


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

代码文件:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @PNViewFind
    DrawerLayout mainLayout;

    @PNViewFind
    RelativeLayout main_fl_drawer;

    @PNViewFind
    RelativeLayout right;

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

        PNViewFind.Bind.init(this);

        mainLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
                //获取屏幕的宽高
                WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
                Display display = manager.getDefaultDisplay();
                //设置右面的布局位置  根据左面菜单的right作为右面布局的left   左面的right+屏幕的宽度(或者right的宽度这里是相等的)为右面布局的right
                right.layout(main_fl_drawer.getRight(), 0, main_fl_drawer.getRight() + display.getWidth(), display.getHeight());
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                super.onDrawerStateChanged(newState);
            }
        });
    }

    @Override
    public void onClick(View v) {
        mainLayout.openDrawer(main_fl_drawer);
    }
}

你可能感兴趣的:(技术类,android,android,studio,移动开发,安卓,viewpager)