仿扇贝单词----自定义可拖拽控件

仿扇贝单词—-自定义可拖拽控件

最近在做项目时需要实现一个可以拖动的控件,用于在有限的屏幕内显示更多的内容.先给大家看一下效果图.
这里写图片描述

这个效果的主要特点有以下几点:
1.只有按住拖拽的按钮时才可以拖动,下面的内容布局无法拖动.
2.内容布局的触摸事件处理.判断当前的点击位置是否在拖拽控件内,如果在则消耗掉该事件,反之则传递到内部.
1.首先是布局

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <RelativeLayout
        android:id="@+id/rl_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="button"/>
    </RelativeLayout>
    <com.iyuba.myapplication.view.DragView
        android:id="@+id/dgview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/iv_drag"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:src="@mipmap/ic_drag_handle_black_24dp"
            />
        <RelativeLayout
            android:id="@+id/rl"
            android:background="#009688"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值