Android SeekBar的使用——简单案例

seekBar.setOnSeekBarChangeListener监听

自动重写3个方法:

onStopTrackingTouch://拖动后

onStartTrackingTouch://拖动前

onProgressChanged://拖动中

 

1. [代码]layout     

01<?xml version="1.0" encoding="utf-8"?>
02<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
03    android:orientation="vertical" android:layout_width="fill_parent"
04    android:layout_height="fill_parent">
05    <SeekBar android:id="@+id/SeekBar01" android:layout_width="fill_parent"
06        android:layout_height="wrap_content" android:max="100"
07        android:progress="50" android:secondaryProgress="100"></SeekBar>
08    <TextView android:id="@+id/TextView1" android:layout_width="fill_parent"
09        android:layout_height="wrap_content" android:text="" />
10    <TextView android:id="@+id/TextView2" android:layout_width="fill_parent"
11        android:layout_height="wrap_content" android:text="" />
12</LinearLayout>

2. [代码]Test_SeekBar.java     

01package com.Aina.Android;
02
03import android.app.Activity;
04import android.os.Bundle;
05import android.widget.SeekBar;
06import android.widget.TextView;
07
08public class Test_SeekBar extends Activity implements SeekBar.OnSeekBarChangeListener{
09    /** Called when the activity is first created. */
10    private SeekBar seekBar;
11    private TextView textView1,textView2;
12    @Override
13    public void onCreate(Bundle savedInstanceState) {
14        super.onCreate(savedInstanceState);
15        setContentView(R.layout.main);
16        seekBar = (SeekBar) this.findViewById(R.id.SeekBar01);
17        textView1 = (TextView) this.findViewById(R.id.TextView1);
18        textView2 = (TextView) this.findViewById(R.id.TextView2);
19        seekBar.setOnSeekBarChangeListener(this);//添加事件监听
20    }
21    //拖动中
22    @Override
23    public void onProgressChanged(SeekBar seekBar, int progress,
24            boolean fromUser) {
25        this.textView1.setText("当前值:"+progress);
26
27    }
28    //开始拖动
29    @Override
30    public void onStartTrackingTouch(SeekBar seekBar) {
31        this.textView2.setText("拖动中...");
32
33    }
34    //结束拖动
35    @Override
36    public void onStopTrackingTouch(SeekBar seekBar) {
37        this.textView2.setText("拖动完毕");
38
39    }
40}

转载于:https://my.oschina.net/u/1463230/blog/264281

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值