android之实现SeekBar拖动组件

android之实现SeekBar拖动组件:

布局:layout/activity_main.xml

<LinearLayout 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"
android:orientation="vertical"
>


<SeekBar
android:id="@+id/sb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
/>
</LinearLayout>

java代码:

package com.litsoft.main;


import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.Process;
import android.os.SystemClock;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;


public class MainActivity extends ActionBarActivity implements OnSeekBarChangeListener{
private SeekBar sb1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();

}


private void init() {
// TODO Auto-generated method stub
sb1 = (SeekBar) findViewById(R.id.sb1);
sb1.setOnSeekBarChangeListener(this);
}


@Override
public void onProgressChanged(SeekBar seekBar, int process, boolean fromUser) {
// TODO Auto-generated method stub
Log.i("main", "进度:"+process);
}


@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
Log.i("main", "开始拖动seekBar");
}


@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
Log.i("main", "结束拖动seekBar");
}





}

效果:

android之实现SeekBar拖动组件_第1张图片android之实现SeekBar拖动组件_第2张图片

 

 

你可能感兴趣的:(android)