全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Android自定义滑动解锁控件使用详解

最近的项目里用到了,在网上找不到合适的,于是自己写了个简单的,带回弹效果:

可以自定义的属性有:

<!-- 滑动解锁控件 xml配置属性 -->
<declare-styleable name="SlideToUnlockView">
 <attr name="slideImageViewWidth" format="dimension"/><!-- 滑块宽度 -->
 <attr name="slideImageViewResId" format="reference"/><!-- 滑块资源id -->
 <attr name="slideImageViewResIdAfter" format="reference"/><!-- 滑动到右边时,滑块资源id -->
 <attr name="viewBackgroundResId" format="reference"/><!-- 背景资源id -->
 <attr name="textHint" format="string"/><!-- 文本内容 -->
 <attr name="textSize" format="integer"/><!-- 文本字号 -->
 <attr name="textColorResId" format="color"/><!-- 文本字色 -->
 <attr name="slideThreshold" format="float"/><!-- 滑动阈值,默认是0.5,当右滑距离不满整个控件宽度的0.5,就会回弹至左边 -->
</declare-styleable>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 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"
 xmlns:chuck="http://schemas.android.com/apk/res-auto"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.qdong.slidetounlockdemo.MainActivity">


 <RelativeLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:id="@+id/relativeLayout">

 <!-- chuck:textSize="14sp"
   chuck:textColorResId="@color/colorWhite"-->
 <com.qdong.slide_to_unlock_view.CustomSlideToUnlockView
  android:id="@+id/slide_to_unlock"
  android:layout_width="match_parent"
  android:layout_height="50dp"


  chuck:viewBackgroundResId="@drawable/shape_round_normal_green"
  chuck:slideImageViewWidth="@dimen/slide_width"
  chuck:slideImageViewResId="@mipmap/icon_slide"
  chuck:slideImageViewResIdAfter="@mipmap/ic_launcher"
  chuck:slideThreshold="0.5"
  chuck:textSize="6"
  chuck:textHint="@string/hint"
  chuck:textColorResId="@color/colorWhite"

  >

 </com.qdong.slide_to_unlock_view.CustomSlideToUnlockView>

 </RelativeLayout>

 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="reset"
 android:id="@+id/button"
 android:layout_below="@+id/relativeLayout"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="150dp"/>

 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/tv_text"
 android:text="slide distance:"
 android:layout_alignBottom="@+id/button"
 android:layout_centerHorizontal="true"
 android:layout_marginBottom="60dp"/>

</RelativeLayout>

MainActivity:

public class MainActivity extends AppCompatActivity {

 private com.qdong.slide_to_unlock_view.CustomSlideToUnlockView mCustomSlideToUnlockView;
 private TextView tv_text;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 mCustomSlideToUnlockView= (com.qdong.slide_to_unlock_view.CustomSlideToUnlockView) findViewById(R.id.slide_to_unlock);
 tv_text= (TextView) findViewById(R.id.tv_text);

 CustomSlideToUnlockView.CallBack callBack=new CustomSlideToUnlockView.CallBack() {
  @Override
  public void onSlide(int distance) {
  tv_text.setText("slide distance:"+distance);
  }

  @Override
  public void onUnlocked() {
  tv_text.setText("onUnlocked");
  }
 };
 mCustomSlideToUnlockView.setmCallBack(callBack);
 findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View view) {
  mCustomSlideToUnlockView.resetView();
  }
 });
 }
}

下载地址:

https://github.com/506954774/AndroidCustomSlideToUnlockView

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# Android  # 滑动解锁  # Android自定义控件实现可左右滑动的导航条  # Android控件之SlidingDrawer(滑动式抽屉)详解与实例分享  # Android开源堆叠滑动控件仿探探效果  # Android自定义控件ScrollView实现上下滑动功能  # Android实现可滑动的自定义日历控件  # Android控件SeekBar仿淘宝滑动验证效果  # Android自定义View实现随手势滑动控件  # Android仿微信列表滑动删除之可滑动控件(一)  # Android自定义控件实现滑动开关效果  # Android自定义双向滑动控件  # 滑块  # 就会  # 下载地址  # 找不到  # 写了  # 自定义  # 大家多多  # 解锁  # 里用  # 在网上  # version  # encoding  # xmlns  # RelativeLayout  # utf  # activity_main  # color  # textColorResId  # integer  # slideThreshold 


相关文章: 电商网站制作公司有哪些,1688网是什么意思?  中山网站推广排名,中山信息港登录入口?  实现点击下箭头变上箭头来回切换的两种方法【推荐】  如何基于云服务器快速搭建网站及云盘系统?  北京制作网站的公司,北京铁路集团官方网站?  如何在IIS中新建站点并配置端口与IP地址?  建站之星免费模板:自助建站系统与智能响应式一键生成  建站主机选购指南:核心配置优化与品牌推荐方案  佛山网站制作系统,佛山企业变更地址网上办理步骤?  如何快速上传自定义模板至建站之星?  建站之星安装需要哪些步骤及注意事项?  c++23 std::expected怎么用 c++优雅处理函数错误返回【详解】  网站制作费用多少钱,一个网站的运营,需要哪些费用?  建站之星安装路径如何正确选择及配置?  淘宝制作网站有哪些,淘宝网官网主页?  如何在服务器上三步完成建站并提升流量?  南京网站制作费用,南京远驱官方网站?  如何在阿里云完成域名注册与建站?  php json中文编码为null的解决办法  Thinkphp 中 distinct 的用法解析  微信小程序制作网站有哪些,微信小程序需要做网站吗?  非常酷的网站设计制作软件,酷培ai教育官方网站?  如何设置并定期更换建站之星安全管理员密码?  建站之星后台密码如何安全设置与找回?  魔方云NAT建站如何实现端口转发?  建站之星后台密码遗忘或太弱?如何重置与强化?  如何在建站之星网店版论坛获取技术支持?  制作宣传网站的软件,小红书可以宣传网站吗?  北京的网站制作公司有哪些,哪个视频网站最好?  官网网站制作腾讯审核要多久,联想路由器newifi官网  在线ppt制作网站有哪些,请推荐几个好的课件下载的网站?  北京网站制作费用多少,建立一个公司网站的费用.有哪些部分,分别要多少钱?  制作充值网站的软件,做人力招聘为什么要自己交端口钱?  名字制作网站免费,所有小说网站的名字?  建站为何优先选择香港服务器?  我的世界制作壁纸网站下载,手机怎么换我的世界壁纸?  宁波免费建站如何选择可靠模板与平台?  广州建站公司哪家好?十大优质服务商推荐  表情包在线制作网站免费,表情包怎么弄?  已有域名能否直接搭建网站?  如何通过虚拟主机空间快速建站?  Swift中swift中的switch 语句  建站之星安装后如何配置SEO及设计样式?  网站制作中优化长尾关键字挖掘的技巧,建一个视频网站需要多少钱?  网站设计制作书签怎么做,怎样将网页添加到书签/主页书签/桌面?  如何在VPS电脑上快速搭建网站?  如何在建站之星绑定自定义域名?  javascript中的try catch异常捕获机制用法分析  c# Task.Yield 的作用是什么 它和Task.Delay(1)有区别吗  XML的“混合内容”是什么 怎么用DTD或XSD定义 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。