展会信息港展会大全

Android SeekBar拖动条的使用
来源:互联网   发布日期:2015-10-03 11:13:53   浏览:2274次  

导读:Android SeekBar拖动条的使用1.[代码]layout?xml version=1.0 encoding=utf-8?LinearLayout xmlns:android=http://schemas.android.com/apk/res/androidandroid:orientation=vertical android:l......

Android SeekBar拖动条的使用

1. [代码]layout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent">

<SeekBar android:id="@+id/SeekBar01" android:layout_width="fill_parent"

android:layout_height="wrap_content" android:max="100"

android:progress="50" android:secondaryProgress="100"></SeekBar>

<TextView android:id="@+id/TextView1" android:layout_width="fill_parent"

android:layout_height="wrap_content" android:text="" />

<TextView android:id="@+id/TextView2" android:layout_width="fill_parent"

android:layout_height="wrap_content" android:text="" />

</LinearLayout>

2. [代码]Test_SeekBar.java

package com.Aina.Android;

import android.app.Activity;

import android.os.Bundle;

import android.widget.SeekBar;

import android.widget.TextView;

public class Test_SeekBar extends Activity implements SeekBar.OnSeekBarChangeListener{

/** Called when the activity is first created. */

private SeekBar seekBar;

private TextView textView1,textView2;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

seekBar = (SeekBar) this.findViewById(R.id.SeekBar01);

textView1 = (TextView) this.findViewById(R.id.TextView1);

textView2 = (TextView) this.findViewById(R.id.TextView2);

seekBar.setOnSeekBarChangeListener(this);//添加事件监听

}

//拖动中

@Override

public void onProgressChanged(SeekBar seekBar, int progress,

boolean fromUser) {

this.textView1.setText("当前值:"+progress);

}

//开始拖动

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

this.textView2.setText("拖动中...");

}

//结束拖动

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

this.textView2.setText("拖动完毕");

}

}

赞助本站

人工智能实验室

相关热词: SeekBar 拖动条

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港