Android 侧滑缩放菜单(HorizontalScrollView简单实现)

本文介绍如何使用HorizontalScrollView实现Android侧滑菜单,包括列表视图布局、自定义View、主布局设计,以及缩放和覆盖式菜单效果的实现。详细解释了菜单隐藏和拖动过程中的坐标变化,利用开源库实现菜单平滑过渡和内容视图的缩放。
摘要由CSDN通过智能技术生成

参考鸿洋博客的一篇文章:
http://blog.csdn.net/lmj623565791/article/details/39257409


最终效果图

项目运行图


一、菜单布局

采用列表视图ListView

left_menu.xml

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/color"
    android:paddingTop="5dp" 
    android:layout_marginTop="80dp">
</ListView>

其中android:entries用于通过数组资源为ListView指定列表项(也可以在代码中通过Adapter来为ListView指定要显示的列表项)

values\arrays.xml

<resources>
    <string-array name="color">
        <item></item>
        <item></item>
        <item></item>
        <item>绿</item>
    </string-array>
</resources>

二、主布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"            
    xmlns:my="http://schemas.android.com/apk/res/com.example.slidemenutest"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<!-- 自定义View,等下会定义MyView类来实现 -->
    <com.example.slidemenutest.MyView
        android:id="@+id/menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/menu_background"
        my:rightPadding="150dp" >

        <!-- 自定义View里面只允许一个控件,所以要嵌套 -->

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

            <!-- 导入刚才的菜单布局 -->
            <include layout="@layout/left_menu" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值