欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android之SeekBar控件用法详解

程序员文章站 2024-03-31 18:36:58
mainactivity.java package com.example.mars_2400_seekbar; import android.suppor...

mainactivity.java

package com.example.mars_2400_seekbar;

import android.support.v7.app.actionbaractivity;
import android.support.v7.app.actionbar;
import android.support.v4.app.fragment;
import android.app.activity;
import android.os.bundle;
import android.view.layoutinflater;
import android.view.menu;
import android.view.menuitem;
import android.view.view;
import android.view.viewgroup;
import android.widget.seekbar;
import android.widget.seekbar.onseekbarchangelistener;
import android.widget.textview;
import android.os.build;

public class mainactivity extends activity implements onseekbarchangelistener {
  private textview tv;
  private seekbar sb;

  @override
  protected void oncreate(bundle savedinstancestate) {
    super.oncreate(savedinstancestate);
    setcontentview(r.layout.activity_main);
    tv = (textview) findviewbyid(r.id.textview1);
    sb = (seekbar) findviewbyid(r.id.seekbar);
    sb.setonseekbarchangelistener(this);
  }

  @override
  public void onprogresschanged(seekbar seekbar, int progress,
      boolean fromuser) {
    // todo auto-generated method stub
    tv.settext("progress is " + progress
        + (fromuser ? " trigger" : " nontrigger") + " by user.");
  }


     @override
      public void onstarttrackingtouch(seekbar seekbar) {
          // todo auto-generated method stub
  	      system.out.println("onstart-->"+seekbar.getprogress());
      }

     @override
      public void onstoptrackingtouch(seekbar seekbar) {
          // todo auto-generated method stub
  	      system.out.println("onstop-->"+seekbar.getprogress());
      }


  @override
  public boolean oncreateoptionsmenu(menu menu) {
    // inflate the menu; this adds items to the action bar if it is present.
    getmenuinflater().inflate(r.menu.main, menu);
    return true;
  }

}

 activity_main.xml

 

<?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"
     >
 
<textview android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/textview1"/>

<seekbar android:id="@+id/seekbar"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
 </linearlayout>

以上就是小编为大家带来的android之seekbar控件用法详解的全部内容了,希望对大家有所帮助,多多支持~