dependencies {
// your dependencies ...
compile 'com.linklink.views:slide_to_unlock_view:1.0.0'
}
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,就会回弹至左边
<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>
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();
}
});
}
}