• 侧滑界面的实现


    侧滑界面——向右滑动或者是点击左上角的一个文本进行侧滑

    主界面activity_main.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     xmlns:tools="http://schemas.android.com/tools"
     4     android:layout_width="match_parent"
     5     android:layout_height="match_parent"
     6     android:orientation="vertical"
     7     android:padding="10dp"
     8     android:id="@+id/drawerLayout"
     9     tools:context=".MainActivity">
    10 
    11     <RelativeLayout
    12         android:layout_width="match_parent"
    13         android:layout_height="match_parent"
    14         android:layout_marginLeft="10dp">
    15 
    16         <TextView
    17             android:id="@+id/slide_name"
    18             android:layout_width="match_parent"
    19             android:layout_height="wrap_content"
    20             android:text="侧滑"
    21             android:layout_marginTop="10dp"
    22             android:textSize="15sp"
    23             android:textColor="#000000"
    24             />
    25 
    26     </RelativeLayout>
    27 
    28     <!--侧滑界面,必须设置layout_gravity属性,表示侧滑方向-->
    29     <RelativeLayout
    30         android:layout_gravity="start"
    31         android:id="@+id/ll"
    32         android:background="#FFFF00"
    33         android:orientation="vertical"
    34         android:layout_width="300dp"
    35         android:layout_height="match_parent">
    36 
    37         <Button
    38             android:id="@+id/btn_add"
    39             android:layout_width="match_parent"
    40             android:layout_height="wrap_content"
    41             android:text="添加账户"
    42             android:layout_marginTop="20dp"
    43             android:background="#1E86FD"
    44             />
    45 
    46     </RelativeLayout>
    47 
    48 </androidx.drawerlayout.widget.DrawerLayout>

     MainActivity.java

     1 public class MainActivity extends AppCompatActivity{
     2     //侧滑
     3     private TextView mSlideName;
     4     @Override
     5     protected void onCreate(Bundle savedInstanceState) {
     6         super.onCreate(savedInstanceState);
     7         setContentView(R.layout.activity_main);
     8         //侧滑
     9         final DrawerLayout drawerLayout=findViewById(R.id.drawerLayout);
    10         //给按钮添加一个监听器
    11         mSlideName=findViewById(R.id.slide_name);
    12         Intent intent = getIntent();
    13         mSlideName.setText(intent.getStringExtra("user_name"));
    14         mSlideName.setOnClickListener(new View.OnClickListener() {
    15             @Override
    16             public void onClick(View view) {
    17                 //打开侧滑菜单
    18                 drawerLayout.openDrawer(GravityCompat.START);
    19             }
    20         });
    21     }
    22 }    

    以上便是完成侧滑的相应步骤

  • 相关阅读:
    JavaScript ---Function
    win7(x64)安装scrapy框架
    [转]mysql性能优化-慢查询分析、优化索引和配置
    [原创]win7环境下搭建eclipse+python+django开发环境
    [原创]Python/Django使用富文本编辑器XHeditor上传本地图片
    Ubuntu下mysql使用
    [整理] mysql操作
    [原创]Sql2008 使用TVP批量插入数据
    一个js获取数组下标的函数
    深入理解js的prototype以及prototype的一些应用
  • 原文地址:https://www.cnblogs.com/miao-com/p/14491513.html
Copyright © 2020-2023  润新知