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

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

15058979021.gif?201762385020

可以自定义的属性有:

activity_main.xml:

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">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/relativeLayout">

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"

>

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"/>

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"/>

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();

}

});

}

}

下载地址:

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

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值