Code Monkey home page Code Monkey logo

androidcustomslidetounlockview's Introduction

AndroidCustomSlideToUnlockView

安卓自定义滑动解锁控件

添加依赖:

dependencies {
// your dependencies ...
compile 'com.linklink.views:slide_to_unlock_view:1.0.0'
}

效果图:

img

可以自定义的属性:

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

xml :

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

MainActivity.java :

package com.qdong.slidetounlockdemo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.qdong.slide_to_unlock_view.CustomSlideToUnlockView;


public class MainActivity extends AppCompatActivity {

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.