侧滑菜单的编写
来源:互联网 发布:mysql查询语句大全实例 编辑:程序博客网 时间:2024/06/07 04:42
布局文件:
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.heart.liuli.stroys.activity.MainActivity">
<!--侧滑菜单的布局(将被拉出和隐藏的布局)-->
<LinearLayout android:id="@+id/inner" android:layout_width="@dimen/menu_width" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/dark" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/px15" > <Button android:id="@+id/btn_exit" android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/red" android:text="退 出" android:textSize="@dimen/menu_textsize" android:textColor="@color/white" android:padding="@dimen/px5" android:layout_alignParentBottom="true" android:layout_marginLeft="@dimen/px10" android:layout_marginRight="@dimen/px10" /> </RelativeLayout> </LinearLayout> </LinearLayout> <!--最外层布局 (显示数据的布局)--> <LinearLayout android:id="@+id/outer" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/colorPrimaryDark" > <!--拉出侧滑菜单--> <RelativeLayout android:id="@+id/relative_push" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/px10" android:padding="@dimen/px5" android:layout_marginRight="@dimen/px10"> <ImageView android:layout_width="@dimen/menu_image_width" android:layout_height="@dimen/menu_image_height" android:src="@mipmap/icon_log" /> </RelativeLayout> <RelativeLayout android:id="@+id/relative_edit" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/px10" android:padding="@dimen/px5" android:gravity="right" > <ImageView android:layout_width="@dimen/menu_image_width" android:layout_height="@dimen/menu_image_height" android:src="@mipmap/icon_edit" /> </RelativeLayout> </LinearLayout> </LinearLayout> </LinearLayout></FrameLayout>
java文件:
public class MainActivity extends BaseActivity { @ @BindView(R.id.inner) LinearLayout linear_inner; @BindView(R.id.relative_push) RelativeLayout relative_push; @BindView(R.id.outer) LinearLayout linear_outer; private boolean menuOpenOrNot=false; //默认那个菜单式关闭的 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); } /** * 点击事件的处理 * @param view */ @OnClick({R.id.relative_push}) public void onClick(View view) { switch (view.getId()) { case R.id.relative_push: //要完成工作 //第一步:首先咋要判断这个menu菜单的状态(关/开) if (menuOpenOrNot) { //说明菜单当前的状态是打开的,一旦成立那么我们应该关闭它 new MenuOpenOrCloseThread(10, linear_inner.getMeasuredWidth(), 1,linear_outer).start(); menuOpenOrNot = false; } else { //说明菜单式是关闭的,那么一旦成立的话我们需要打开它 //如何打开这个菜 new MenuOpenOrCloseThread(10, linear_inner.getMeasuredWidth(), 0,linear_outer).start(); menuOpenOrNot = true; } break; } }}MenuOpenOrCloseThread文件:public class MenuOpenOrCloseThread extends Thread { int time; //移动的次数 int speed; //每一次移动的距离 int i=0; int menuCloseOrOpen; View view; //menuCloseOrOpen:用来区分是从左边忘右边进行滑动还是从右边往左边进行滑动 0--->从左往右 1---->从右往左 public MenuOpenOrCloseThread(int time,int distanceX,int menuCloseOrOpen,View view){ speed=distanceX/time; this.time=time; this.menuCloseOrOpen=menuCloseOrOpen; this.view = view; } @Override public void run() { while(i<time){ try { Thread.sleep(25); Message msg=Message.obtain(); msg.arg1=speed; msg.arg2=menuCloseOrOpen; msg.what=100; handler.sendMessage(msg); i++; } catch (InterruptedException e) { e.printStackTrace(); } } } /** * 刷新UI */ Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { switch (msg.what){ case 100: //打开菜单 int speed=msg.arg1; int menuCloseOrOpen=msg.arg2; if(menuCloseOrOpen==0){ view.scrollBy(-speed,0); //这个移动是有方向的负数表示的是从左边向右边进行移动,正数表示的是从右边向左边进行移动 }else{ view.scrollBy(speed,0); //这个移动是有方向的负数表示的是从左边向右边进行移动,正数表示的是从右边向左边进行移动 } break; } } };}
1 0
- 侧滑菜单的编写
- MENUBAR菜单的编写
- 弹出式菜单的编写
- DELPHI的奇异菜单的编写
- DELPHI的奇异菜单的编写
- 编写JavaScript代码,控制菜单的显示
- 我的第一次编写菜单应用程序
- (孙鑫)菜单的原理及编写
- C51编写菜单的示例程序
- dtree编写简单的树形菜单组件
- 编写横向菜单的HTML代码架构
- Android中popWindow弹出菜单的编写
- Android的选项菜单,用代码编写
- 编写一个类似记事本的菜单
- 编写一个简单的菜单操作界面
- 事件委托的二级菜单编写
- MFC_菜单的编写及应用
- 侧滑菜单的实现
- springmvc全局异常处理
- 关于Tinker学习
- 2016/10/23
- Redis安装与使用
- sklearn 下距离的度量 —— sklearn.metrics
- 侧滑菜单的编写
- 网页播放mp3-网页打开即播放
- Map的四种遍历方式
- 如何让Myeclipse的包名嵌套
- 8天学通MongoDB——第五天 主从复制
- WebApi实现验证授权Token,WebApi生成文档等
- spring与mybatis的几种整合方式。
- 数据结构示例之展示矩阵高、低、主对角线值
- 删除list中某个对象属性为空的对象使用迭代器