app直播源码,Android 滑动拼图验证码控件
app直播源码,Android 滑动拼图验证码控件
1.视图布局文件:activity_main.xml。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.slideimage.MainActivity">
<com.slideimage.SlideImageView
android:id="@+id/slide_image_view"
android:layout_width="240dp"
android:layout_height="150dp"
android:layout_marginTop="50dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<View
android:id="@+id/flash_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintLeft_toLeftOf="@id/slide_image_view"
app:layout_constraintRight_toRightOf="@id/slide_image_view"
app:layout_constraintTop_toTopOf="@id/slide_image_view"
app:layout_constraintBottom_toBottomOf="@id/slide_image_view"
android:background="@mipmap/drag_flash"/>
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_marginTop="220dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<TextView
android:id="@+id/show_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:textSize="20sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="320dp"
android:text="重新初始化"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
2.在Activity中使用滑块验证:MainActivity.java。
public class MainActivity extends AppCompatActivity {
private SeekBar seekBar;
private Button button1;
private SlideImageView slideImageView;
private TextView resultText;
private View flashView;
private static final int flashTime = 800;
private long timeStart = 0;
private float timeUsed;
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = findViewById(R.id.seekBar1);
button1 = findViewById(R.id.button1);
slideImageView = findViewById(R.id.slide_image_view);
flashView = findViewById(R.id.flash_view);
resultText = findViewById(R.id.show_result);
slideImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.slide_bg));
seekBar.setMax(10000);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
slideImageView.setMove(progress*0.0001);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
timeStart = System.currentTimeMillis();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
以上就是app直播源码,Android 滑动拼图验证码控件, 更多内容欢迎关注之后的文章