• android之SeekBar控件用法


    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>
  • 相关阅读:
    java读取和设置配置文件中的属性参数
    win7 x64位 下安装 Vue 开发环境
    mysql 字段中 去除空格
    easyuiswitchbutton 样式错位问题
    解决windows下环境变量太长而无法添加的问题
    windows10我的电脑打不开
    vs无法打开包括文件corecrt.h
    Python,C++中点云 .las转.pcd
    yolov5目标检测基本思想
    python安装第三方包的方法
  • 原文地址:https://www.cnblogs.com/zhuawang/p/3675348.html
Copyright © 2020-2023  润新知