DrawerLayout 模仿QQ 测滑菜单

此博客转自 https://blog.csdn.net/mhhyoucom/article/details/80102887



DrawerLayout 模仿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>
  • 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

代码文件:

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);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值