• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > 自己实现android侧滑菜单

自己实现android侧滑菜单

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了android侧滑菜单实现,android侧滑菜单,android侧滑菜单demo,android 侧滑式菜单,android侧滑菜单框架等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

自己实现android侧滑菜单


当今的android应用设计中,一种主流的设计方式就是会拥有一个侧滑菜单,以图为证:</div> </div>  </div> 实现这样的侧滑效果,在5.0以前我们用的最多的就是SlidingMenu这个开源框架,而5.0之后,google推出了自己的侧滑实现库,那就是DrawerLayout,它的用法比SlidingMenu更简单,而且因为是google的亲生儿子,所以现在人们更倾向于使用DrawerLayout,但是再怎么说,这些都是别人实现好的东西,我们只是拿来用用而已,对于内部的原理,很多程序员却不怎么明白,在接下来的文章中我会通过android中的一些基础控件来实现于此相似的效果,当然,也许还有很多种实现方式,但是基本的原理是类似的。</div>

 

首先,我们会用到一个控件:HorizontalScrollView 从名字我们就可以了解到,这是一种水平滑动的控件,也就是当内容大于屏幕的宽度的时候,可以左右滑动来使超出屏幕的内容显示在屏幕上。

第一步:把菜单的布局简单的写出来

<span style="font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:14px;"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E-->
<relativelayout android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <linearlayout android:layout_centerinparent="true" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical">
        <relativelayout android:layout_height="wrap_content" android:layout_width="wrap_content">
            <imageview android:id="@+id/img1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher">
            <textview android:id="@+id/text1" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_torightof="@id/img1" android:layout_width="wrap_content" android:text="item1">


        </textview></imageview></relativelayout>


        <relativelayout android:layout_height="wrap_content" android:layout_width="wrap_content">
            <imageview android:id="@+id/img2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher">
            <textview android:id="@+id/text2" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_torightof="@id/img2" android:layout_width="wrap_content" android:text="item1">


        </textview></imageview></relativelayout>


        <relativelayout android:layout_height="wrap_content" android:layout_width="wrap_content">
            <imageview android:id="@+id/img3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher">
            <textview android:id="@+id/text3" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_torightof="@id/img3" android:layout_width="wrap_content" android:text="item1">


        </textview></imageview></relativelayout>


        <relativelayout android:layout_height="wrap_content" android:layout_width="wrap_content">
            <imageview android:id="@+id/img4" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher">
            <textview android:id="@+id/text4" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_torightof="@id/img4" android:layout_width="wrap_content" android:text="item1">


        </textview></imageview></relativelayout>


        <relativelayout android:layout_height="wrap_content" android:layout_width="wrap_content">
            <imageview android:id="@+id/img5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/ic_launcher">
            <textview android:id="@+id/text5" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_torightof="@id/img5" android:layout_width="wrap_content" android:text="item1">


        </textview></imageview></relativelayout>
    </linearlayout>
</relativelayout></span></span>
</div> 第二步:写出整体布局</div>
<span style="font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:14px;"><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E-->
<linearlayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<googleplay.xiaokai.com.qq.slidmenu android:background="@drawable/img_frame_background" android:id="@+id/horscrview" android:layout_height="match_parent" android:layout_width="wrap_content" android:scrollbars="none">
    <linearlayout android:layout_height="match_parent" android:layout_width="wrap_content" android:orientation="horizontal">
        <include layout="@layout/left_menulayout">
        <linearlayout android:background="@drawable/qq" android:layout_height="match_parent" android:layout_width="match_parent">
        </linearlayout>
    </include></linearlayout>
</googleplay.xiaokai.com.qq.slidmenu>
</linearlayout></span>
</span>
</div> </div> 第三步:继承HorizontalScrollView实现自定义控件</div>
<span style="font-size:18px;">package googleplay.xiaokai.com.qq;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;


/**
 * Created by 孙晓凯 on 2016/3/27.
 */
public class SlidMenu extends HorizontalScrollView {
    int mScreenWit;//屏幕宽度
    int mRightWithScr;
    LinearLayout mWrap;
    ViewGroup mMenu;
    ViewGroup mContent;
    int mMenuWidth ;
    private boolean flag;


    public SlidMenu(Context context, AttributeSet attrs) {
        super(context, attrs);
        //得到屏幕的宽度
        WindowManager winmana = (WindowManager) context.getSystemService(context.WINDOW_SERVICE);
        DisplayMetrics metris = new DisplayMetrics();
        winmana.getDefaultDisplay().getMetrics(metris);
        mScreenWit = metris.widthPixels;//得到的是像素
        //把50dp转换成像素
        mRightWithScr = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, context.getResources().getDisplayMetrics());


    }


    public SlidMenu(Context context) {
        super(context);


    }


    @Override
    protected void o



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 自己实现android侧滑菜单

相关文章

  • 2017-05-225.2.4 Fragment实例精讲——底部导航栏+ViewPager滑动切换页面
  • 2017-05-26网站偶尔访问不了故障总结
  • 2017-05-26用Kotlin实现Android定制视图(KAD 06),kotlinandroid
  • 2017-05-26服务器DELL R710配置安装centos经验之谈
  • 2017-05-26andorid build tools 19.1,andorid19.1
  • 2017-05-26Android studio1.5.1 NDK配置开发
  • 2017-05-26XAMARIN ANDROID 二维码扫描示例,xamarinandroid
  • 2017-05-26ListView的&#160;addHeaderView,addheaderview
  • 2017-05-26用户登录(Material Design + Data-Binding + MVP架构模式)实现,data-bindingmvp
  • 2017-05-26提升Android ListView性能的几个技巧

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android应用自定义View绘制方法手册
    • QQ互联登录以及非官方正版应用报100044错误,互联100044
    • 安卓应用程序的签名
    • linux设备驱动程序之时钟管理(4)----原来是孩儿他爹娘
    • 多线程中使用curl致coredump问题
    • popupwindow展示,popupwindow
    • 从源码的角度理解四大组件的工作过程——Android开发艺术探索笔记
    • 【React Native开发】React Native控件之ViewPagerAndroid讲解以及美团首页顶部效果实例(17)
    • 自动化运维之cobbler批量部署操作系统(一)
    • 2.4.2 Date & Time组件(上)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有