android开发之GestureDetector手势识别(调节音量、亮度、快进和后退)

本文介绍了如何利用Android的GestureDetector类实现手势识别,以达到调节音量、屏幕亮度以及快进后退的效果。首先,需要继承FragmentActivity并实现OnGestureListener和OnTouchListener。接着,获取UI布局中的控件,然后获取视频播放窗口尺寸。在OnTouchListener的监听方法中,通过GestureDetector处理复杂手势,如在onDown()方法中响应开始手势,在onScroll()方法中完成实际的手势操作,从而实现功能。
摘要由CSDN通过智能技术生成

这里写图片描述

写UI布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical" >

    <include
        android:id="@+id/root_layout"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        layout="@layout/video_layout" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

    <com.zanelove.gesturedetectordemo.views.MyVideoView
            android:id="@+id/tv_pro_play"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    <LinearLayout
            android:id="@+id/ll_player_controller"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="#c0000000"
            android:gravity="center"
            android:orientation="horizontal"
            android:visibility="gone">

        <ImageView
                android:id="@+id/iv_play_pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:src="@drawable/btn_pause" />

        <TextView
                android:id="@+id/tv_playing_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="00:00"
                android:textColor="@android:color/darker_gray"
                android:textSize="15sp" />

        <SeekBar
                android:id="@+id/sb_video_progress"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_weight="2" />

        <TextView
                android:id="@+id/tv_total_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:text="00:00"
                android:textColor="@android:color/darker_gray"
                and
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值