国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android拖動條的實現代碼

2019-12-12 01:58:15
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android拖動條的具體代碼,供大家參考,具體內容如下

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="當前值:50"   android:textSize="16sp"   android:paddingTop="40dp"   android:paddingLeft="15dp"   tools:layout_editor_absoluteY="0dp"   tools:layout_editor_absoluteX="0dp" />  <!-- 拖動條 -->  <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;//拖動條  @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("當前值:"+progress);    }     @Override    public void onStartTrackingTouch(SeekBar seekBar) {     Toast.makeText(MainActivity.this,"開始滑動",Toast.LENGTH_SHORT).show();    }     @Override    public void onStopTrackingTouch(SeekBar seekBar) {     Toast.makeText(MainActivity.this,"結束滑動",Toast.LENGTH_SHORT).show();    }   });  } } 

效果圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 含山县| 平湖市| 邵东县| 东辽县| 丹寨县| 尼木县| 大庆市| 海南省| 武夷山市| 崇礼县| 中方县| 新营市| 兖州市| 长春市| 民勤县| 宜川县| 从江县| 肥西县| 利川市| 喜德县| 邵武市| 望城县| 大兴区| 合作市| 淅川县| 宁陕县| 朝阳县| 双流县| 刚察县| 瓦房店市| 鸡东县| 张家口市| 横峰县| 老河口市| 城固县| 栖霞市| 堆龙德庆县| 德安县| 米脂县| 金阳县| 克什克腾旗|