本文實(shí)例為大家分享了Android拖動(dòng)條的具體代碼,供大家參考,具體內(nèi)容如下
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.amy.seekbartest.MainActivity"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="當(dāng)前值:50" android:textSize="16sp" android:paddingTop="40dp" android:paddingLeft="15dp" tools:layout_editor_absoluteY="0dp" tools:layout_editor_absoluteX="0dp" /> <!-- 拖動(dòng)條 --> <SeekBar android:id="@+id/seekBar1" android:layout_height="wrap_content" android:max="100" android:layout_width="match_parent" android:progress="50" android:paddingTop="10dp" tools:layout_editor_absoluteY="0dp" tools:layout_editor_absoluteX="32dp" /> </android.support.constraint.ConstraintLayout>
MainActivity.java
package com.amy.seekbartest;  import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast;  public class MainActivity extends AppCompatActivity {   private SeekBar seekBar;//拖動(dòng)條  @Override  protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.activity_main);   final TextView result = (TextView) findViewById(R.id.textView1);   seekBar = (SeekBar) findViewById(R.id.seekBar1);   seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {    @Override    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {     result.setText("當(dāng)前值:"+progress);    }     @Override    public void onStartTrackingTouch(SeekBar seekBar) {     Toast.makeText(MainActivity.this,"開始滑動(dòng)",Toast.LENGTH_SHORT).show();    }     @Override    public void onStopTrackingTouch(SeekBar seekBar) {     Toast.makeText(MainActivity.this,"結(jié)束滑動(dòng)",Toast.LENGTH_SHORT).show();    }   });  } } 效果圖:
	
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注