仿QQ侧滑和酷狗侧滑效果

今天来写的是关于侧滑的,说道侧滑,我们可以想导用什么来实现呢?首先肯定是系统为我们写好的DrawerLayout来写,或者用ViewGroup再加上一些手势处理,下面我来写的是自定义view继承自我们的HorizontalScrollView。先看一下实际的QQ效果和酷狗的实际效果先说一下实现思路:就是在自定义的ViewGroup下面放两个布局,一个是菜单布局,一个是内容布局,
摘要由CSDN通过智能技术生成

今天来写的是关于侧滑的,说道侧滑,我们可以想导用什么来实现呢?首先肯定是系统为我们写好的DrawerLayout来写,或者用ViewGroup再加上一些手势处理,下面我来写的是自定义view继承自我们的HorizontalScrollView。

先看一下实际的QQ效果和酷狗的实际效果


先说一下实现思路:

就是在自定义的ViewGroup下面放两个布局,一个是菜单布局,一个是内容布局,看看我们在代码中使用情况吧

activity_main:

<?xml version="1.0" encoding="utf-8"?>
<moocollege.cn.kugougouslidemenu.KuGouSlideMenu xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@mipmap/home_bg_menu"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:menuRightMargin="100dp"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <include layout="@layout/layout_menu" />

        <include layout="@layout/layout_content" />
    </LinearLayout>

</moocollege.cn.kugougouslidemenu.KuGouSlideMenu>


当然你要是以为直接这样做就可以的话,在自定义的viewGropu中不做处理,布局会乱的。想看效果的可以试试

不做任何处理的

public class KuGouSlideMenu extends HorizontalScrollView {

    public KuGouSlideMenu(Context context) {
        this(context, null);
    }

    public KuGouSlideMenu(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public KuGouSlideMenu(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    
    }
}

layout_menu
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/layout_menu_top"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_above="@+id/layout_bottom"
        android:layout_marginTop="20dp"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/enter_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="23dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/user_head_iv"
                android:layout_width="56dp"
                android:layout_height="56dp"
                android:src="@mipmap/toux2" />

            <TextView
                android:id="@+id/user_name_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="16dp"
                android:text="登录/注册"
                android:textColor="#FFFFFF"
                android:textSize="18sp
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值